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);
        }
Beispiel #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 || 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);
        }
        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);
        }
		private static void CompareResourceBinding(InputBindingDescription expected,
			ResourceBinding actual)
		{
			Assert.AreEqual(expected.BindCount, actual.BindCount);
			Assert.AreEqual(expected.BindPoint, actual.BindPoint);
			Assert.AreEqual((int) expected.Dimension, (int) actual.Dimension);
			Assert.AreEqual((int) expected.Flags, (int) actual.Flags);
			Assert.AreEqual(expected.Name, actual.Name);
			if (expected.NumSamples != -1 || actual.NumSamples != uint.MaxValue)
				Assert.AreEqual(expected.NumSamples, actual.NumSamples);
			Assert.AreEqual((int) expected.ReturnType, (int) actual.ReturnType);
			Assert.AreEqual((int) expected.Type, (int) actual.Type);
		}