public ShaderTypeMember(MatrixParameter param, ShaderGpuProgramType programType) { ProgramType = programType; Name = param.Name; ShaderType = new ShaderType(param, programType); Index = (uint)param.Index; }
public void Export(ShaderWriter writer, ShaderType type) { if (GlobalKeywords.Length > 0) { writer.Write("Keywords { "); foreach (string keyword in GlobalKeywords) { writer.Write("\"{0}\" ", keyword); } if (HasLocalKeywords(writer.Version)) { foreach (string keyword in LocalKeywords) { writer.Write("\"{0}\" ", keyword); } } writer.Write("}\n"); writer.WriteIndent(5); } #warning TODO: convertion (DX to HLSL) ShaderGpuProgramType programType = GetProgramType(writer.Version); writer.Write("\"{0}", programType.ToProgramDataKeyword(writer.Platform, type)); if (ProgramData.Length > 0) { writer.Write("\n"); writer.WriteIndent(5); writer.WriteShaderData(ref this); } writer.Write('"'); }
public ShaderTypeMember(VectorParameter param, ShaderGpuProgramType programType) { this.ProgramType = programType; Name = param.Name; ShaderType = new ShaderType(param, programType); Index = (uint)param.Index; }
public static int GetMajorDXVersion(this ShaderGpuProgramType _this) { switch (_this) { case ShaderGpuProgramType.DX10Level9Vertex: case ShaderGpuProgramType.DX10Level9Pixel: case ShaderGpuProgramType.DX11PixelSM40: case ShaderGpuProgramType.DX11VertexSM40: case ShaderGpuProgramType.DX11GeometrySM40: return(4); case ShaderGpuProgramType.DX11PixelSM50: case ShaderGpuProgramType.DX11VertexSM50: case ShaderGpuProgramType.DX11GeometrySM50: case ShaderGpuProgramType.DX11HullSM50: case ShaderGpuProgramType.DX11DomainSM50: return(5); case ShaderGpuProgramType.DX12RayTracingSM63: return(6); default: throw new Exception($"Unexpected program type {_this}"); } }
public static DXProgramType ToDXProgramType(this ShaderGpuProgramType _this) { switch (_this) { case ShaderGpuProgramType.DX10Level9Pixel: case ShaderGpuProgramType.DX11PixelSM40: case ShaderGpuProgramType.DX11PixelSM50: return(DXProgramType.PixelShader); case ShaderGpuProgramType.DX10Level9Vertex: case ShaderGpuProgramType.DX11VertexSM40: case ShaderGpuProgramType.DX11VertexSM50: return(DXProgramType.VertexShader); case ShaderGpuProgramType.DX11GeometrySM40: case ShaderGpuProgramType.DX11GeometrySM50: return(DXProgramType.GeometryShader); case ShaderGpuProgramType.DX11HullSM50: return(DXProgramType.HullShader); case ShaderGpuProgramType.DX11DomainSM50: return(DXProgramType.DomainShader); default: throw new Exception($"Unexpected program type {_this}"); } }
internal static DXProgramType GetDXProgramType(ShaderGpuProgramType prgramType) { switch (prgramType) { case ShaderGpuProgramType.DX11PixelSM40: case ShaderGpuProgramType.DX11PixelSM50: return(DXProgramType.PixelShader); case ShaderGpuProgramType.DX11VertexSM40: case ShaderGpuProgramType.DX11VertexSM50: return(DXProgramType.VertexShader); case ShaderGpuProgramType.DX11GeometrySM40: case ShaderGpuProgramType.DX11GeometrySM50: return(DXProgramType.GeometryShader); case ShaderGpuProgramType.DX11HullSM50: return(DXProgramType.HullShader); case ShaderGpuProgramType.DX11DomainSM50: return(DXProgramType.DomainShader); default: throw new Exception($"Unexpected program type {prgramType}"); } }
public ShaderSubProgram(BinaryReader reader) { //LoadGpuProgramFromData // 201509030 - Unity 5.3 // 201510240 - Unity 5.4 // 201608170 - Unity 5.5 // 201609010 - Unity 5.6, 2017.1 & 2017.2 // 201708220 - Unity 2017.3, Unity 2017.4 & Unity 2018.1 // 201802150 - Unity 2018.2 magic = reader.ReadInt32(); m_ProgramType = (ShaderGpuProgramType)reader.ReadInt32(); reader.BaseStream.Position += 12; if (magic >= 201608170) //5.5.0 and up { reader.BaseStream.Position += 4; } var keywordCount = reader.ReadInt32(); m_Keywords = new string[keywordCount]; for (int i = 0; i < keywordCount; i++) { m_Keywords[i] = reader.ReadAlignedString(); } m_ProgramCode = reader.ReadBytes(reader.ReadInt32()); reader.AlignStream(); //TODO }
public Variable(MatrixParameter param, ShaderGpuProgramType programType) { ShaderType = new ShaderType(param, programType); Name = param.Name ?? throw new Exception("Variable name cannot be null"); NameIndex = param.NameIndex; Index = param.Index; ArraySize = param.ArraySize; }
private static ShaderTextExporter ShaderExporterInstantiator(ShaderGpuProgramType programType) { if (s_isSupported && programType.IsDX()) { return(new ShaderDXExporter()); } return(Shader.DefaultShaderExporterInstantiator(programType)); }
public VariableChunk(ref BufferBinding bufferBinding, int constantBufferIndex, uint variableOffset, ShaderGpuProgramType programType) { m_constantBufferIndex = constantBufferIndex; m_programType = programType; majorVersion = programType.GetMajorDXVersion(); m_variables = new Variable[] { Variable.CreateResourceBindVariable(programType) }; BuildVariableHeaders(variableOffset); }
public void WriteShaderData(ref ShaderSubProgram subProgram) { ShaderGpuProgramType programType = subProgram.GetProgramType(Version); GPUPlatform graphicApi = programType.ToGPUPlatform(Platform); ShaderTextExporter exporter = m_exporterInstantiator.Invoke(Shader.File.Version, graphicApi); exporter.Export(this, ref subProgram); }
public VariableChunk(ref ConstantBuffer constantBuffer, int constantBufferIndex, uint variableOffset, ShaderGpuProgramType programType) { m_constantBufferIndex = constantBufferIndex; m_programType = programType; majorVersion = programType.GetMajorDXVersion(); m_variables = BuildVariables(ref constantBuffer); BuildVariableHeaders(variableOffset); }
public Variable(VectorParameter param, ShaderGpuProgramType programType) { ShaderType = new ShaderType(param, programType); Name = param.Name ?? throw new Exception("Variable name cannot be null"); NameIndex = param.NameIndex; Index = param.Index; ArraySize = param.ArraySize; Length = (uint)(param.Dim * 4); }
public Variable(MatrixParameter param, ShaderGpuProgramType programType) { ShaderType = new ShaderType(param, programType); Name = param.Name ?? throw new Exception("Variable name cannot be null"); NameIndex = param.NameIndex; Index = param.Index; ArraySize = param.ArraySize; Length = (uint)(param.RowCount * param.ColumnCount * 4); }
public Variable(VectorParameter param, ShaderGpuProgramType prgramType) { ShaderType = new ShaderType(param, prgramType); Name = param.Name; NameIndex = param.NameIndex; Index = param.Index; ArraySize = param.ArraySize; Dim = param.Dim; if (Name == null) throw new Exception("Variable name cannot be null"); }
public ShaderType(MatrixParameter matrixParam, ShaderGpuProgramType programType) { ShaderVariableClass = ShaderVariableClass.MatrixColumns; ShaderVariableType = GetVariableType(matrixParam.Type); Rows = matrixParam.RowCount; Columns = matrixParam.ColumnCount; ElementCount = (ushort)matrixParam.ArraySize; MemberCount = 0; MemberOffset = 0; m_programType = programType; }
public ShaderType(MatrixParameter matrixParam, ShaderGpuProgramType programType) { ShaderVariableClass = ShaderVariableClass.MatrixColumns; //TODO: matrix colums or rows? ShaderVariableType = GetVariableType(matrixParam.Type); Rows = matrixParam.RowCount; Columns = matrixParam.RowCount; ElementCount = 0; MemberCount = 0; MemberOffset = 0; this.programType = programType; }
public static bool IsMetal(this ShaderGpuProgramType _this) { switch (_this) { case ShaderGpuProgramType.MetalFS: case ShaderGpuProgramType.MetalVS: return(true); default: return(false); } }
public static ShaderTextExporter DefaultShaderExporterInstantiator(ShaderGpuProgramType programType) { if (programType.IsGL()) { return(new ShaderGLESExporter()); } if (programType.IsMetal()) { return(new ShaderMetalExporter()); } return(new ShaderUnknownExporter(programType)); }
public ShaderType(VectorParameter vectorParam, ShaderGpuProgramType programType) { Members = Array.Empty <ShaderTypeMember>(); ShaderVariableClass = vectorParam.Dim > 1 ? ShaderVariableClass.Vector : ShaderVariableClass.Scalar; ShaderVariableType = GetVariableType(vectorParam.Type); Rows = 1; Columns = vectorParam.Dim; ElementCount = (ushort)vectorParam.ArraySize; MemberCount = 0; MemberOffset = 0; m_programType = programType; }
static string ProgramTypeToName(ShaderGpuProgramType programType) { switch (programType) { case ShaderGpuProgramType.Unknown: return("UNK"); case ShaderGpuProgramType.GLLegacy: case ShaderGpuProgramType.GLES31AEP: case ShaderGpuProgramType.GLES31: case ShaderGpuProgramType.GLES3: case ShaderGpuProgramType.GLES: case ShaderGpuProgramType.GLCore32: case ShaderGpuProgramType.GLCore41: case ShaderGpuProgramType.GLCore43: return("GL"); case ShaderGpuProgramType.DX9VertexSM20: case ShaderGpuProgramType.DX9VertexSM30: case ShaderGpuProgramType.DX10Level9Vertex: case ShaderGpuProgramType.DX11VertexSM40: case ShaderGpuProgramType.DX11VertexSM50: case ShaderGpuProgramType.MetalVS: case ShaderGpuProgramType.PSVertex: return("VS"); case ShaderGpuProgramType.DX9PixelSM20: case ShaderGpuProgramType.DX9PixelSM30: case ShaderGpuProgramType.DX10Level9Pixel: case ShaderGpuProgramType.DX11PixelSM40: case ShaderGpuProgramType.DX11PixelSM50: case ShaderGpuProgramType.MetalFS: case ShaderGpuProgramType.PSPixel: return("PS"); case ShaderGpuProgramType.DX11GeometrySM40: case ShaderGpuProgramType.DX11GeometrySM50: return("GS"); case ShaderGpuProgramType.DX11HullSM50: return("HS"); case ShaderGpuProgramType.DX11DomainSM50: return("DS"); case ShaderGpuProgramType.Console: return("CON"); default: return("UNK"); } }
public Variable(string name, int index, int sizeToAdd, ShaderGpuProgramType prgramType) { if (sizeToAdd % 4 != 0 || sizeToAdd <= 0) throw new Exception($"Invalid dummy variable size {sizeToAdd}"); var param = new VectorParameter(name, ShaderParamType.Int, index, sizeToAdd / 4); ShaderType = new ShaderType(param, prgramType); Name = name; NameIndex = -1; Index = index; ArraySize = 0; Type = ShaderParamType.Int; Dim = (byte)(sizeToAdd / 4); if (Name == null) throw new Exception("Variable name cannot be null"); }
public ShaderType(VectorParameter vectorParam, ShaderGpuProgramType programType) { ShaderVariableClass = vectorParam.Dim > 1 ? ShaderVariableClass.Vector : ShaderVariableClass.Scalar; ShaderVariableType = GetVariableType(vectorParam.Type); Rows = 1; Columns = vectorParam.Dim; ElementCount = 0; MemberCount = 0; MemberOffset = 0; this.programType = programType; }
public ResourceChunk(Version version, ref ShaderSubProgram shaderSubprogram) { ShaderGpuProgramType programType = shaderSubprogram.GetProgramType(version); m_majorVersion = (byte)programType.GetMajorDXVersion(); m_resourceBindingOffset = m_majorVersion >= 5 ? (uint)60 : (uint)28; m_resourceBindings = new ResourceBindingChunk(ref shaderSubprogram, m_resourceBindingOffset, m_nameLookup); m_constantBufferOffset = m_resourceBindingOffset + m_resourceBindings.Size; m_constantBuffers = new ConstantBufferChunk(version, ref shaderSubprogram, m_constantBufferOffset, m_nameLookup); m_creatorStringOffset = m_constantBufferOffset + m_constantBuffers.Size; m_creatorString = "uTinyRipper"; m_chunkSize = m_creatorStringOffset + (uint)m_creatorString.Length + 1; m_programType = programType.ToDXProgramType(); }
public static bool IsDX9(this ShaderGpuProgramType _this) { switch (_this) { case ShaderGpuProgramType.DX9PixelSM20: case ShaderGpuProgramType.DX9PixelSM30: case ShaderGpuProgramType.DX9VertexSM20: case ShaderGpuProgramType.DX9VertexSM30: return(true); default: return(false); } }
public static Variable CreateResourceBindVariable(ShaderGpuProgramType programType) { Variable variable = new Variable(); variable.Name = "$Element"; var param = new VectorParameter(variable.Name, ShaderParamType.UInt, 0, 1); variable.ShaderType = new ShaderType(param, programType); variable.NameIndex = -1; variable.Index = 0; variable.ArraySize = param.ArraySize; variable.Length = 4; variable.Type = ShaderParamType.UInt; return(variable); }
public ShaderType(StructParameter structParameter, ShaderGpuProgramType programType) { Members.AddRange(structParameter.VectorMembers.Select(p => new ShaderTypeMember(p, programType))); Members.AddRange(structParameter.MatrixMembers.Select(p => new ShaderTypeMember(p, programType))); Members = Members .OrderBy(v => v.Index) .ToList(); ShaderVariableClass = ShaderVariableClass.Struct; //TODO: matrix colums or rows? ShaderVariableType = ShaderVariableType.Void; Rows = 0; Columns = 0; ElementCount = 0; MemberCount = (ushort)Members.Count(); MemberOffset = 0; m_programType = programType; }
public static bool IsGL(this ShaderGpuProgramType _this) { switch (_this) { case ShaderGpuProgramType.GLLegacy: case ShaderGpuProgramType.GLCore32: case ShaderGpuProgramType.GLCore41: case ShaderGpuProgramType.GLCore43: case ShaderGpuProgramType.GLES: case ShaderGpuProgramType.GLES3: case ShaderGpuProgramType.GLES31: case ShaderGpuProgramType.GLES31AEP: return(true); default: return(false); } }
public static int GetMajorVersion(ShaderGpuProgramType prgramType) { switch (prgramType) { case ShaderGpuProgramType.DX11PixelSM40: case ShaderGpuProgramType.DX11VertexSM40: case ShaderGpuProgramType.DX11GeometrySM40: return 4; case ShaderGpuProgramType.DX11PixelSM50: case ShaderGpuProgramType.DX11VertexSM50: case ShaderGpuProgramType.DX11GeometrySM50: case ShaderGpuProgramType.DX11HullSM50: case ShaderGpuProgramType.DX11DomainSM50: return 5; default: throw new Exception($"Unexpected program type {prgramType}"); } }
public ConstantBufferChunk(Version version, ref ShaderSubProgram shaderSubprogram, uint contantBufferOffset, Dictionary <string, uint> nameLookup) { m_shaderSubprogram = shaderSubprogram; m_contantBufferOffset = contantBufferOffset; m_nameLookup = nameLookup; ShaderGpuProgramType programType = shaderSubprogram.GetProgramType(version); uint headerSize = (uint)Count * 24; uint variableOffset = contantBufferOffset + headerSize; int constantBufferIndex = 0; List <VariableChunk> variables = new List <VariableChunk>(); for (int i = 0; i < shaderSubprogram.ConstantBuffers.Length; i++) { ref ConstantBuffer constantBuffer = ref shaderSubprogram.ConstantBuffers[i]; VariableChunk variableChunk = new VariableChunk(ref constantBuffer, constantBufferIndex++, variableOffset, programType); variables.Add(variableChunk); variableOffset += variableChunk.Size; }