Ejemplo n.º 1
0
        public static ResourceBinding Parse(BytecodeReader reader, BytecodeReader resourceBindingReader, ShaderVersion target)
        {
            uint nameOffset = resourceBindingReader.ReadUInt32();
            var  nameReader = reader.CopyAtOffset((int)nameOffset);
            var  result     = new ResourceBinding
            {
                Name       = nameReader.ReadString(),
                Type       = (ShaderInputType)resourceBindingReader.ReadUInt32(),
                ReturnType = (ResourceReturnType)resourceBindingReader.ReadUInt32(),
                Dimension  = (ShaderResourceViewDimension)resourceBindingReader.ReadUInt32(),
                NumSamples = resourceBindingReader.ReadUInt32(),
                BindPoint  = resourceBindingReader.ReadUInt32(),
                BindCount  = resourceBindingReader.ReadUInt32(),
                Flags      = (ShaderInputFlags)resourceBindingReader.ReadUInt32()
            };

            if (target.MajorVersion == 5 && target.MinorVersion == 1)
            {
                result.m_IsSM51 = true;

                result.SpaceIndex = resourceBindingReader.ReadUInt32();
                result.ID         = resourceBindingReader.ReadUInt32();
            }
            else
            {
                result.ID = result.BindPoint;
            }
            return(result);
        }
        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)
            {
                var isVersion5_1 = target.MajorVersion == 5 && target.MinorVersion == 1;
                if (isVersion5_1)
                {
                    var unknown0 = headerReader.ReadUInt32();
                    Debug.Assert(unknown0 == 625218323, $"Unexpected RDef Header identifier {unknown0}");
                }
                else
                {
                    string rd11 = headerReader.ReadUInt32().ToFourCcString();
                    if (rd11 != "RD11")
                    {
                        throw new ParseException("Expected RD11.");
                    }
                }

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

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

                var resourceBindingStride = headerReader.ReadUInt32();
                Debug.Assert(resourceBindingStride == (isVersion5_1 ? 40 : 32),
                             $"Unexpected resource binding stride {resourceBindingStride}");

                //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);
        }