Example #1
0
        private Dictionary <string, ShaderVariable> ConvertToPushConstantDict(ShaderVariable[] pushConstants)
        {
            Dictionary <string, ShaderVariable> pushConstantDict = new Dictionary <string, ShaderVariable>();

            for (int i = 0; i < pushConstants.Length; i++)
            {
                ShaderVariable pushConstant = pushConstants[i];
                pushConstantDict[pushConstant.Name] = pushConstant;
            }
            return(pushConstantDict);
        }
Example #2
0
        internal static List <ShaderVariable> Parse(IEnumerable <string> fields)
        {
            List <ShaderVariable> variables = new List <ShaderVariable>();

            uint offset = 0;

            for (int i = 0; i < fields.Count(); i++)
            {
                string variableLine = Util.KillDuplicateWhiteSpaces(fields.ElementAt(i)).Replace("[ ]", "[]");
                if (string.IsNullOrEmpty(variableLine))
                {
                    continue;
                }

                string[] segments = variableLine.Split(' ');

                string name = segments[1];


                string glslType = segments[0];

                uint size = 0;
                Type type;
                if (Constants.GlslToNetType.ContainsKey(glslType))
                {
                    type = Constants.GlslToNetType[glslType];
                    size = Constants.TypeToSize[type];
                }
                else
                {
                    type = System.Reflection.Assembly.GetEntryAssembly().DefinedTypes.Where(n => n.Name == glslType).First();
                    size = (uint)Marshal.SizeOf(type);
                }


                ShaderVariable shaderVariable = new ShaderVariable(name, type)
                {
                    Size   = size,
                    Offset = offset,
                };

                variables.Add(shaderVariable);

                offset += size;
            }

            return(variables);
        }
Example #3
0
        public ShaderVariable[] GetPushConstants()
        {
            ShaderVariable[] pushConstants = new ShaderVariable[0];

            IEnumerable <string> fields = _segmentCollection.GetPushConstantFields();

            if (fields != null)
            {
                pushConstants = ShaderVariableParser.Parse(fields).ToArray();

                for (int i = 0; i < pushConstants.Length; i++)
                {
                    pushConstants[i].ShaderStage = ShaderStage;
                }
            }

            return(pushConstants);
        }
Example #4
0
        public void SetPushConstant(CommandBuffer commandBuffer, string pushConstantName, Matrix4 value)
        {
            ShaderVariable pushConstant = _pushConstantDict[pushConstantName];

            commandBuffer.CmdPushConstants(PipelineLayout, pushConstant.ShaderStage, pushConstant.Offset, pushConstant.Size, new IntPtr(&value));
        }