Exemplo n.º 1
0
        public static ResourceDefinitionChunk Parse(BytecodeReader reader)
        {
            var headerReader = reader.CopyAtCurrentPosition();

            uint constantBufferCount   = headerReader.ReadUInt32();
            uint constantBufferOffset  = headerReader.ReadUInt32();
            uint resourceBindingCount  = headerReader.ReadUInt32();
            uint resourceBindingOffset = headerReader.ReadUInt32();
            var  target = ShaderVersion.ParseRdef(headerReader);
            uint flags  = headerReader.ReadUInt32();

            var creatorOffset = headerReader.ReadUInt32();
            var creatorReader = reader.CopyAtOffset((int)creatorOffset);
            var creator       = creatorReader.ReadString();

            var result = new ResourceDefinitionChunk
            {
                Target  = target,
                Flags   = (ShaderFlags)flags,
                Creator = creator
            };

            if (target.MajorVersion == 5 || target.ProgramType == ProgramType.LibraryShader)
            {
                if (target.MinorVersion == 0)
                {
                    string rd11 = headerReader.ReadUInt32().ToFourCcString();
                    if (rd11 != "RD11")
                    {
                        throw new ParseException("Expected RD11.");
                    }
                }
                else
                {
                    var unknown0 = headerReader.ReadUInt32();
                    Debug.Assert(unknown0 == 625218323);
                }

                var unknown1 = headerReader.ReadUInt32();                 // TODO
                Debug.Assert(unknown1 == 60);

                var constantBufferStride = headerReader.ReadUInt32();
                Debug.Assert(constantBufferStride == 24);

                var resourceBindingStride = headerReader.ReadUInt32();
                Debug.Assert(resourceBindingStride == (target.MinorVersion == 0 ? 32 : 40));

                //Shader Variable Stride?
                var unknown4 = headerReader.ReadUInt32();
                Debug.Assert(unknown4 == 40);

                var unknown5 = headerReader.ReadUInt32();
                Debug.Assert(unknown5 == 36);

                //Shader Type Member Stride?
                var unknown6 = headerReader.ReadUInt32();
                Debug.Assert(unknown6 == 12);

                result.InterfaceSlotCount = headerReader.ReadUInt32();
            }

            var constantBufferReader = reader.CopyAtOffset((int)constantBufferOffset);

            for (int i = 0; i < constantBufferCount; i++)
            {
                result.ConstantBuffers.Add(ConstantBuffer.Parse(reader, constantBufferReader, result.Target));
            }

            var resourceBindingReader = reader.CopyAtOffset((int)resourceBindingOffset);

            for (int i = 0; i < resourceBindingCount; i++)
            {
                result.ResourceBindings.Add(ResourceBinding.Parse(reader, resourceBindingReader, target));
            }

            return(result);
        }
Exemplo n.º 2
0
        public static ResourceDefinitionChunk Parse(BytecodeReader reader)
        {
            var headerReader = reader.CopyAtCurrentPosition();

            uint constantBufferCount   = headerReader.ReadUInt32();
            uint constantBufferOffset  = headerReader.ReadUInt32();
            uint resourceBindingCount  = headerReader.ReadUInt32();
            uint resourceBindingOffset = headerReader.ReadUInt32();
            var  target = ShaderVersion.ParseRdef(headerReader);
            uint flags  = headerReader.ReadUInt32();

            var creatorOffset = headerReader.ReadUInt32();
            var creatorReader = reader.CopyAtOffset((int)creatorOffset);
            var creator       = creatorReader.ReadString();

            var result = new ResourceDefinitionChunk
            {
                Target  = target,
                Flags   = (ShaderFlags)flags,
                Creator = creator
            };

            if (target.MajorVersion >= 5)
            {
                string rd11 = headerReader.ReadUInt32().ToFourCcString();
                if (rd11 != "RD11")
                {
                    throw new ParseException("Expected RD11.");
                }

                var unknown1 = headerReader.ReadUInt32();                 // TODO
                Debug.Assert(unknown1 == 60);

                var unknown2 = headerReader.ReadUInt32();
                Debug.Assert(unknown2 == 24);

                var unknown3 = headerReader.ReadUInt32();
                Debug.Assert(unknown3 == 32);

                var unknown4 = headerReader.ReadUInt32();
                Debug.Assert(unknown4 == 40);

                var unknown5 = headerReader.ReadUInt32();
                Debug.Assert(unknown5 == 36);

                var unknown6 = headerReader.ReadUInt32();
                Debug.Assert(unknown6 == 12);

                result.InterfaceSlotCount = headerReader.ReadUInt32();
            }

            var constantBufferReader = reader.CopyAtOffset((int)constantBufferOffset);

            for (int i = 0; i < constantBufferCount; i++)
            {
                result.ConstantBuffers.Add(ConstantBuffer.Parse(reader, constantBufferReader, result.Target));
            }

            var resourceBindingReader = reader.CopyAtOffset((int)resourceBindingOffset);

            for (int i = 0; i < resourceBindingCount; i++)
            {
                result.ResourceBindings.Add(ResourceBinding.Parse(reader, resourceBindingReader));
            }

            return(result);
        }