public static EffectChunk Parse(BytecodeReader reader, uint size) { var headerReader = reader.CopyAtCurrentPosition(); var result = new EffectChunk(); var header = result.Header = EffectHeader.Parse(headerReader); var bodyOffset = header.Version.MajorVersion < 5 ? 0x4C : 0x60; var footerOffset = (int)(result.Header.FooterOffset + bodyOffset); var bodyReader = reader.CopyAtOffset((int)bodyOffset); var footerReader = reader.CopyAtOffset(footerOffset); var version = header.Version; for (int i = 0; i < header.ConstantBuffers; i++) { result.LocalBuffers.Add(EffectBuffer.Parse(bodyReader, footerReader, version, false)); } for (int i = 0; i < header.ObjectCount; i++) { result.LocalVariables.Add(EffectObjectVariable.Parse(bodyReader, footerReader, version, false)); } for (int i = 0; i < header.SharedConstantBuffers; i++) { result.SharedBuffers.Add(EffectBuffer.Parse(bodyReader, footerReader, version, true)); } for (int i = 0; i < header.SharedObjectCount; i++) { result.SharedVariables.Add(EffectObjectVariable.Parse(bodyReader, footerReader, version, true)); } if (header.Version.MajorVersion >= 5) { for (int i = 0; i < header.InterfaceVariableCount; i++) { result.InterfaceVariables.Add(EffectInterfaceVariable.Parse(bodyReader, footerReader, version)); } for (int i = 0; i < header.GroupCount; i++) { result.Groups.Add(EffectGroup.Parse(bodyReader, footerReader, header.Version)); } } else { for (int i = 0; i < header.Techniques; i++) { result.Techniques.Add(EffectTechnique.Parse(bodyReader, footerReader, header.Version)); } } return(result); }
public static EffectBuffer Parse(BytecodeReader reader, BytecodeReader bufferReader, ShaderVersion version, bool isShared) { var result = new EffectBuffer(); var nameOffset = result.NameOffset = bufferReader.ReadUInt32(); var nameReader = reader.CopyAtOffset((int)nameOffset); result.Name = nameReader.ReadString(); result.BufferSize = bufferReader.ReadUInt32(); result.BufferType = (ConstantBufferType)bufferReader.ReadUInt32(); result.VariableCount = bufferReader.ReadUInt32(); result.RegisterNumber = bufferReader.ReadUInt32(); if (!isShared) { var unknown0 = bufferReader.ReadUInt32(); //TODO: Unknown0 //Debug.Assert(result.Unknown0 == 0, $"EffectBuffer.Unknown0: {result.Unknown0}"); } for (int i = 0; i < result.VariableCount; i++) { result.Variables.Add(EffectNumericVariable.Parse(reader, bufferReader, version, isShared)); } return(result); }
public static void CompareConstantBuffer(EffectConstantBuffer reflectionEffectBuffer, Fx10.EffectBuffer buffer) { var desc = reflectionEffectBuffer.Description; Assert.AreEqual(desc.Name, buffer.Name); Assert.AreEqual(desc.Semantic ?? "", ""); Assert.AreEqual((uint)desc.Flags, 0); Assert.AreEqual(desc.AnnotationCount, 0); Assert.AreEqual(desc.BufferOffset, 0); Assert.AreEqual(desc.ExplicitBindPoint, buffer.RegisterNumber == uint.MaxValue ? 0 : buffer.RegisterNumber); Assert.AreEqual(reflectionEffectBuffer.TypeInfo.Description.Type, (ShaderVariableType)buffer.Type); if (reflectionEffectBuffer.TypeInfo.Description.Type == ShaderVariableType.ConstantBuffer) { var cbufferDesc = reflectionEffectBuffer.GetConstantBuffer().Description; //TODO: Compare cbufferDesc } else { var tbufferDesc = reflectionEffectBuffer.GetTextureBuffer().Description; //TODO: Compare tbufferDesc } }