Ejemplo n.º 1
0
        public int CreateShaderModule(MgShaderStageFlagBits stage)
        {
            var shaderType = ShaderType.VertexShader;

            switch (stage)
            {
            case MgShaderStageFlagBits.FRAGMENT_BIT:
                shaderType = ShaderType.FragmentShader;
                break;

            case MgShaderStageFlagBits.VERTEX_BIT:
                shaderType = ShaderType.VertexShader;
                break;

            case MgShaderStageFlagBits.COMPUTE_BIT:
                shaderType = ShaderType.ComputeShader;
                break;

            case MgShaderStageFlagBits.GEOMETRY_BIT:
                shaderType = ShaderType.GeometryShader;
                break;

            default:
                throw new NotSupportedException();
            }

            return(GL.CreateShader(shaderType));
        }
Ejemplo n.º 2
0
        public void SetCombinedSampler(MgShaderStageFlagBits mask, uint offset, uint samplerIndex)
        {
            switch (mask)
            {
            case MgShaderStageFlagBits.COMPUTE_BIT:
                ComputeOffset       = offset;
                ComputeSamplerIndex = samplerIndex;
                break;

            case MgShaderStageFlagBits.FRAGMENT_BIT:
                FragmentOffset       = offset;
                FragmentSamplerIndex = samplerIndex;
                break;

            case MgShaderStageFlagBits.VERTEX_BIT:
                VertexOffset       = offset;
                VertexSamplerIndex = samplerIndex;
                break;

            default:
                throw new NotSupportedException();
            }
            //DescriptorType = MgDescriptorType.COMBINED_IMAGE_SAMPLER;
            Stage |= mask;
        }
Ejemplo n.º 3
0
        public void CmdPushConstants(IMgPipelineLayout layout, MgShaderStageFlagBits stageFlags, UInt32 offset, UInt32 size, IntPtr pValues)
        {
            var bLayout = (VkPipelineLayout)layout;

            Debug.Assert(bLayout != null);

            Interops.vkCmdPushConstants(this.Handle, bLayout.Handle, (Magnesium.Vulkan.VkShaderStageFlags)stageFlags, offset, size, pValues);
        }
Ejemplo n.º 4
0
        public AmtPipelineLayoutStageResource(
            MgShaderStageFlagBits mask,
            AmtDescriptorSetLayout setLayout,
            IAmtDescriptorSetBindingLocator locator)
        {
            var vertBuffers = new SortedList <uint, AmtPipelineLayoutBufferBinding>();
            var textures    = new SortedList <uint, AmtPipelineLayoutTextureBinding>();
            var samplers    = new SortedList <uint, AmtPipelineLayoutSamplerBinding>();

            Stage = mask;
            Initialise(mask, setLayout, locator, vertBuffers, textures, samplers);
            ConvertToArrays(vertBuffers, textures, samplers);
        }
Ejemplo n.º 5
0
        public AmtPipelineLayoutStageResource(
            MgShaderStageFlagBits mask,
            MgPipelineLayoutCreateInfo createInfo)
        {
            var vertBuffers = new SortedList <uint, AmtPipelineLayoutBufferBinding>();
            var textures    = new SortedList <uint, AmtPipelineLayoutTextureBinding>();
            var samplers    = new SortedList <uint, AmtPipelineLayoutSamplerBinding>();

            Stage = mask;
            foreach (var setLayout in createInfo.SetLayouts)
            {
                var bSetLayout = (AmtDescriptorSetLayout)setLayout;
                Initialise(mask, bSetLayout, null, vertBuffers, textures, samplers);
            }
            ConvertToArrays(vertBuffers, textures, samplers);
        }
Ejemplo n.º 6
0
        public GLActiveUniformBlockInfo GetActiveUniformBlockInfo(int programId, int activeIndex)
        {
            int length;
            var queries = new ProgramProperty[] {
                ProgramProperty.BufferBinding,
                ProgramProperty.BufferDataSize,
                ProgramProperty.ReferencedByFragmentShader,
                ProgramProperty.ReferencedByVertexShader,
                ProgramProperty.ReferencedByGeometryShader,
                ProgramProperty.ReferencedByTessControlShader,
                ProgramProperty.ReferencedByTessEvaluationShader,
            };
            var props = new int[queries.Length];

            GL.GetProgramResource(programId, ProgramInterface.UniformBlock, activeIndex, queries.Length, queries, props.Length, out length, props);

            mErrHandler.CheckGLError();

            int stageIndex = 2;
            MgShaderStageFlagBits stage = props[stageIndex] != 0 ? (MgShaderStageFlagBits.FRAGMENT_BIT) : 0;

            stageIndex += 1;
            stage      |= props[stageIndex] != 0 ? (MgShaderStageFlagBits.VERTEX_BIT) : 0;

            stageIndex += 1;
            stage      |= props[stageIndex] != 0 ? (MgShaderStageFlagBits.GEOMETRY_BIT) : 0;

            stageIndex += 1;
            stage      |= props[stageIndex] != 0 ? (MgShaderStageFlagBits.TESSELLATION_CONTROL_BIT) : 0;

            stageIndex += 1;
            stage      |= props[stageIndex] != 0 ? (MgShaderStageFlagBits.TESSELLATION_EVALUATION_BIT) : 0;


            return(new GLActiveUniformBlockInfo
            {
                BindingIndex = props[0],
                Stride = props[1],
                Stage = stage,
            });
        }
Ejemplo n.º 7
0
        public void SetBuffer(MgShaderStageFlagBits mask, uint offset)
        {
            switch (mask)
            {
            case MgShaderStageFlagBits.COMPUTE_BIT:
                ComputeOffset = offset;
                break;

            case MgShaderStageFlagBits.FRAGMENT_BIT:
                FragmentOffset = offset;
                break;

            case MgShaderStageFlagBits.VERTEX_BIT:
                VertexOffset = offset;
                break;

            default:
                throw new NotSupportedException();
            }
            //DescriptorType = MgDescriptorType.;
            Stage |= mask;
        }
Ejemplo n.º 8
0
        void Initialise(
            MgShaderStageFlagBits mask,
            AmtDescriptorSetLayout setLayout,
            IAmtDescriptorSetBindingLocator locator,
            SortedList <uint, AmtPipelineLayoutBufferBinding> vertBuffers,
            SortedList <uint, AmtPipelineLayoutTextureBinding> textures,
            SortedList <uint, AmtPipelineLayoutSamplerBinding> samplers
            )
        {
            for (var i = 0; i < setLayout.PipelineResources.Length; ++i)
            {
                var resource = setLayout.PipelineResources[i];

                AmtDescriptorSetUpdateKey item = null;
                if (locator != null)
                {
                    if (!locator.TryGetValue(resource.Binding, out item))
                    {
                        item = locator.Add(resource.Binding);
                    }
                }

                if ((resource.Stage & mask) == mask)
                {
                    switch (resource.DescriptorType)
                    {
                    case MgDescriptorType.COMBINED_IMAGE_SAMPLER:
                    case MgDescriptorType.SAMPLED_IMAGE:

                        var texture = new AmtPipelineLayoutTextureBinding
                        {
                            Binding        = resource.Binding,
                            DescriptorType = resource.DescriptorType,
                        };

                        var sampler = new AmtPipelineLayoutSamplerBinding
                        {
                            Binding        = resource.Binding,
                            DescriptorType = resource.DescriptorType,
                        };

                        if (locator != null)
                        {
                            var nextTextureIndex = (uint)textures.Count;
                            var nextSamplerIndex = (uint)samplers.Count;
                            item.SetCombinedSampler(mask, nextTextureIndex, nextSamplerIndex);
                        }

                        textures.Add(texture.Binding, texture);
                        samplers.Add(sampler.Binding, sampler);

                        break;

                    case MgDescriptorType.STORAGE_BUFFER:
                    case MgDescriptorType.STORAGE_BUFFER_DYNAMIC:
                    {
                        var sBuffer = new AmtPipelineLayoutBufferBinding
                        {
                            Binding         = resource.Binding,
                            Category        = AmtPipelineLayoutBufferBindingCategory.StorageBuffer,
                            DescriptorCount = resource.DescriptorCount,
                        };

                        if (locator != null)
                        {
                            var nextOffset = (uint)vertBuffers.Count;
                            item.SetBuffer(mask, nextOffset);
                        }

                        vertBuffers.Add(sBuffer.Binding, sBuffer);
                    }
                    break;

                    case MgDescriptorType.UNIFORM_BUFFER:
                    case MgDescriptorType.UNIFORM_BUFFER_DYNAMIC:
                    {
                        var vBuffer = new AmtPipelineLayoutBufferBinding
                        {
                            Binding         = resource.Binding,
                            Category        = AmtPipelineLayoutBufferBindingCategory.UniformBuffer,
                            DescriptorCount = resource.DescriptorCount,
                        };

                        if (locator != null)
                        {
                            var nextOffset = (uint)vertBuffers.Count;
                            item.SetBuffer(mask, nextOffset);
                        }

                        vertBuffers.Add(vBuffer.Binding, vBuffer);
                    }
                    break;
                    }
                }
            }
        }
Ejemplo n.º 9
0
        internal static int CompileShader(IGLShaderModuleEntrypoint entrypoint, MgShaderStageFlagBits stage, string fileContents, string shaderPrefix, string functionName)
        {
            int retVal = entrypoint.CreateShaderModule(stage);
            // GL.CreateShader(type);
            //string includePath = ".";

            // GLSL has this annoying feature that the #version directive must appear first. But we
            // want to inject some #define shenanigans into the shader.
            // So to do that, we need to split for the part of the shader up to the end of the #version line,
            // and everything after that. We can then inject our defines right there.
            var    strTuple       = VersionSplit(fileContents);
            string versionStr     = strTuple.Item1;
            string shaderContents = strTuple.Item2;

            var builder = new StringBuilder();

            builder.AppendLine(versionStr);
            builder.AppendLine(shaderPrefix);
            builder.Append(shaderContents);

            // APPEND custom function name to replicate custom function name
            builder.Append("void main() { ");
            builder.Append(functionName);
            builder.Append("(); }");

            entrypoint.CompileShaderModule(retVal, builder.ToString());

            //GL.ShaderSource(retVal, builder.ToString());
            //GL.CompileShader(retVal);

            bool isCompiled = entrypoint.IsCompiled(retVal);

            //int compileStatus = 0;
            //GL.GetShader(retVal, ShaderParameter.CompileStatus, out compileStatus);
            //// if (compileStatus != (int)All.True)

            //int glinfoLogLength = 0;
            //GL.GetShader(retVal, ShaderParameter.InfoLogLength, out glinfoLogLength);
            //if (glinfoLogLength > 1)

            bool hasMessages = entrypoint.HasCompilerMessages(retVal);

            if (hasMessages)
            {
                string buffer = entrypoint.GetCompilerMessages(retVal);
                //	GL.GetShaderInfoLog(retVal);
                if (!isCompiled)
                {
                    throw new Exception("Shader Compilation failed for shader with the following errors: " + buffer);
                }
                //				else {
                //					Console.WriteLine("Shader Compilation succeeded for shader '{0}', with the following log:", _shaderFilename);
                //				}
                //
                //				Console.WriteLine(buffer);
            }

            if (!isCompiled)
            {
                entrypoint.DeleteShaderModule(retVal);
                retVal = 0;
            }

            return(retVal);
        }
Ejemplo n.º 10
0
 public void CmdPushConstants(IMgPipelineLayout layout, MgShaderStageFlagBits stageFlags, uint offset, uint size, IntPtr pValues)
 {
     throw new NotImplementedException();
 }