示例#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;
		}
		public static ShaderTypeMember Parse(BytecodeReader reader, BytecodeReader memberReader, ShaderVersion target,
			int indent, bool isFirst, uint parentOffset)
		{
			var nameOffset = memberReader.ReadUInt32();
			var nameReader = reader.CopyAtOffset((int) nameOffset);
			var name = nameReader.ReadString();

			var memberTypeOffset = memberReader.ReadUInt32();

			var offset = memberReader.ReadUInt32();

			var memberTypeReader = reader.CopyAtOffset((int) memberTypeOffset);
			var memberType = ShaderType.Parse(reader, memberTypeReader, target, indent, isFirst, parentOffset + offset);

			return new ShaderTypeMember(parentOffset)
			{
				Name = name,
				Type = memberType,
				Offset = offset
			};
		}
示例#3
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)
			{
				result.StartTexture = variableReader.ReadInt32();
				result.TextureSize = variableReader.ReadInt32();
				result.StartSampler = variableReader.ReadInt32();
				result.SamplerSize = variableReader.ReadInt32();
			}

			return result;
		}
示例#4
0
		public static ShaderType Parse(BytecodeReader reader, BytecodeReader typeReader, ShaderVersion target,
			int indent, bool isFirst, uint parentOffset)
		{
			var result = new ShaderType(indent, isFirst)
			{
				VariableClass = (ShaderVariableClass) typeReader.ReadUInt16(),
				VariableType = (ShaderVariableType) typeReader.ReadUInt16(),
				Rows = typeReader.ReadUInt16(),
				Columns = typeReader.ReadUInt16(),
				ElementCount = typeReader.ReadUInt16()
			};

			var memberCount = typeReader.ReadUInt16();
			var memberOffset = typeReader.ReadUInt32();

			if (target.MajorVersion >= 5)
			{
				var parentTypeOffset = typeReader.ReadUInt32(); // Guessing
				if (parentTypeOffset != 0)
				{
					var parentTypeReader = reader.CopyAtOffset((int) parentTypeOffset);
					var parentTypeClass = (ShaderVariableClass) parentTypeReader.ReadUInt16();
					Debug.Assert(parentTypeClass == ShaderVariableClass.Vector || parentTypeClass == ShaderVariableClass.InterfaceClass);

					var unknown1 = parentTypeReader.ReadUInt16();
					Debug.Assert(unknown1 == 0);
				}

				var unknown2 = typeReader.ReadUInt32();
				if (unknown2 != 0)
				{
					var unknownReader = reader.CopyAtOffset((int) unknown2);
					uint unknown3 = unknownReader.ReadUInt32();
					Debug.Assert(unknown3 == 0 || unknown3 == 5);
				}

				var unknown4 = typeReader.ReadUInt32();
				Debug.Assert(unknown4 == 0 || unknown4 == 1);

				var unknown5 = typeReader.ReadUInt32();
				if (unknown5 != 0)
				{
					var unknownReader = reader.CopyAtOffset((int) unknown5);
					var unknown6 = unknownReader.ReadUInt32();
					Debug.Assert(unknown6 == 580 || unknown6 == 740);
				}

				var parentNameOffset = typeReader.ReadUInt32();
				if (parentNameOffset > 0)
				{
					var parentNameReader = reader.CopyAtOffset((int) parentNameOffset);
					result.BaseTypeName = parentNameReader.ReadString();
				}
			}

			if (memberCount > 0)
			{
				var memberReader = reader.CopyAtOffset((int) memberOffset);
				for (int i = 0; i < memberCount; i++)
					result.Members.Add(ShaderTypeMember.Parse(reader, memberReader, target, indent + 4, i == 0,
						parentOffset));
			}

			return result;
		}