コード例 #1
0
        public static ConstantBuffer Parse(
            BytecodeReader reader, BytecodeReader constantBufferReader,
            ShaderVersion target)
        {
            uint nameOffset = constantBufferReader.ReadUInt32();
            var  nameReader = reader.CopyAtOffset((int)nameOffset);

            uint variableCount  = constantBufferReader.ReadUInt32();
            uint variableOffset = constantBufferReader.ReadUInt32();

            var result = new ConstantBuffer
            {
                Name = nameReader.ReadString()
            };

            var variableReader = reader.CopyAtOffset((int)variableOffset);

            for (int i = 0; i < variableCount; i++)
            {
                result.Variables.Add(ShaderVariable.Parse(reader, variableReader, target, i == 0));
            }

            result.Size       = constantBufferReader.ReadUInt32();
            result.Flags      = (ConstantBufferFlags)constantBufferReader.ReadUInt32();
            result.BufferType = (ConstantBufferType)constantBufferReader.ReadUInt32();

            return(result);
        }
コード例 #2
0
        ///// <summary>
        ///// Gets the corresponding interface slot for a variable that represents an interface pointer.
        ///// </summary>
        //public List<uint> InterfaceSlots { get; private set; }

        public static ShaderVariable Parse(BytecodeReader reader,
                                           BytecodeReader variableReader, ShaderVersion target,
                                           bool isFirst)
        {
            uint nameOffset = variableReader.ReadUInt32();
            var  nameReader = reader.CopyAtOffset((int)nameOffset);

            var  startOffset = variableReader.ReadUInt32();
            uint size        = variableReader.ReadUInt32();
            var  flags       = (ShaderVariableFlags)variableReader.ReadUInt32();

            var typeOffset = variableReader.ReadUInt32();
            var typeReader = reader.CopyAtOffset((int)typeOffset);
            var shaderType = ShaderType.Parse(reader, typeReader, target, 2, isFirst, startOffset);

            var           defaultValueOffset = variableReader.ReadUInt32();
            List <Number> defaultValue       = null;

            if (defaultValueOffset != 0)
            {
                defaultValue = new List <Number>();
                var defaultValueReader = reader.CopyAtOffset((int)defaultValueOffset);
                if (size % 4 != 0)
                {
                    throw new ParseException("Can only deal with 4-byte default values at the moment.");
                }
                for (int i = 0; i < size; i += 4)
                {
                    defaultValue.Add(new Number(defaultValueReader.ReadBytes(4)));
                }
            }

            var name   = nameReader.ReadString();
            var result = new ShaderVariable
            {
                DefaultValue = defaultValue,
                Member       = new ShaderTypeMember(0)
                {
                    Name   = name,
                    Offset = startOffset,
                    Type   = shaderType
                },
                BaseType = name,
                Size     = size,
                Flags    = flags
            };

            if (target.MajorVersion >= 5 || target.ProgramType == ProgramType.LibraryShader)
            {
                result.StartTexture = variableReader.ReadInt32();
                result.TextureSize  = variableReader.ReadInt32();
                result.StartSampler = variableReader.ReadInt32();
                result.SamplerSize  = variableReader.ReadInt32();
            }

            return(result);
        }