CompiledShaderReader(string fn,string shaderType,ConstantBuffer[] cbs , ShaderParameterDescription[] pds,InputBindingDescription[] rbs,ShaderReflection reflec,ShaderBytecode bytec) { cBuffers = cbs; parameterDescriptions = pds; resourceBindings = rbs; filename = fn; typePrefix = shaderType; reflector = reflec; bytecode = bytec; }
private static void CompareParameter(ShaderParameterDescription expected, SignatureParameterDescription actual) { Assert.AreEqual((int)expected.ComponentType, (int)actual.ComponentType); //Assert.AreEqual((int) expected.ReadWriteMask, (int) actual.ReadWriteMask); // TODO: Bug in SharpDX? if (expected.Register != -1 || actual.Register != uint.MaxValue) { Assert.AreEqual(expected.Register, actual.Register); } Assert.AreEqual(expected.SemanticIndex, actual.SemanticIndex); Assert.AreEqual(expected.SemanticName, actual.SemanticName); Assert.AreEqual(expected.Stream, actual.Stream); Assert.AreEqual((int)expected.SystemValueType, (int)actual.SystemValueType); Assert.AreEqual((int)expected.UsageMask, (int)actual.Mask); }
/// <summary> /// 頂点バッファレイアウトのアトリビュートを返す /// </summary> /// <returns></returns> public uint GetVertexLayoutAttribute() { uint attr = 0; ShaderDescription shader_desc = reflector_.Description; for (int i = 0; i < shader_desc.InputParameters; i++) { ShaderParameterDescription param_desc = reflector_.GetInputParameterDescription(i); for (int j = 0; j < sInputSemantics.Length; j++) { if (sInputSemantics[j] == param_desc.SemanticName) { attr |= sInputAttribute[j]; break; } } } return(attr); }
public static CompiledShaderReader ReadCompiledShader(string path) { if (File.Exists(path) && (Path.GetExtension(path) == ".cso")) { byte[] bytes = File.ReadAllBytes(path); ShaderReflection reflecter = new ShaderReflection(bytes); ShaderBytecode bytecode = new ShaderBytecode(bytes); ShaderProfile profile = bytecode.GetVersion(); ConstantBuffer[] cbuffers = new ConstantBuffer[reflecter.Description.ConstantBuffers]; for (int i = 0; i < reflecter.Description.ConstantBuffers; i++) { cbuffers[i] = reflecter.GetConstantBuffer(i);//this might not work } ShaderParameterDescription[] paramdescriptions = new ShaderParameterDescription[reflecter.Description.InputParameters]; for (int i = 0; i < reflecter.Description.InputParameters; i++) { paramdescriptions[i] = reflecter.GetInputParameterDescription(i); } InputBindingDescription[] bindings = new InputBindingDescription[reflecter.Description.BoundResources]; for (int i = 0; i < reflecter.Description.BoundResources; i++) { bindings[i] = reflecter.GetResourceBindingDescription(i); } ConstantBuffer[] cbuffersCOPY = cbuffers.ToArray(); return new CompiledShaderReader(path, profile.GetTypePrefix(), cbuffersCOPY, paramdescriptions.ToArray(), bindings.ToArray(), reflecter, bytecode); } else throw new Exception("Bad path " + path); }
public static InputElement[] GetStreamOutputLayout(this EffectPass pass, out int vertexsize) { vertexsize = 0; if (pass.GeometryShaderDescription.Variable == null) { return(new InputElement[0]); } else { EffectShaderVariable gs = pass.GeometryShaderDescription.Variable; int outputcount = gs.GetShaderDescription(0).OutputParameterCount; InputElement[] elems = new InputElement[outputcount]; int offset = 0; for (int vip = 0; vip < outputcount; vip++) { ShaderParameterDescription sd = gs.GetOutputParameterDescription(0, vip); int componentcount = 0; if (sd.UsageMask.HasFlag(RegisterComponentMaskFlags.ComponentX)) { componentcount++; } if (sd.UsageMask.HasFlag(RegisterComponentMaskFlags.ComponentY)) { componentcount++; } if (sd.UsageMask.HasFlag(RegisterComponentMaskFlags.ComponentZ)) { componentcount++; } if (sd.UsageMask.HasFlag(RegisterComponentMaskFlags.ComponentW)) { componentcount++; } int vsize = 4 * componentcount; string fmt = ""; if (componentcount == 1) { fmt = "R32_"; } if (componentcount == 2) { fmt = "R32G32_"; } if (componentcount == 3) { fmt = "R32G32B32_"; } if (componentcount == 4) { fmt = "R32G32B32A32_"; } switch (sd.ComponentType) { case RegisterComponentType.Float32: fmt += "Float"; break; case RegisterComponentType.SInt32: fmt += "SInt"; break; case RegisterComponentType.UInt32: fmt += "UInt"; break; } Format f = (Format)Enum.Parse(typeof(Format), fmt); InputElement elem = new InputElement(sd.SemanticName, (int)sd.SemanticIndex, f, offset, 0); elems[vip] = elem; offset += vsize; vertexsize += vsize; } return(elems); } }
static InputElement ToInputElement(ShaderParameterDescription desc) { return(new InputElement(desc.SemanticName, desc.SemanticIndex, GetFormat(desc.ComponentType, desc.UsageMask), 0)); }
public void Update(int techid, int passid, ISpread <DX11Resource <IDX11Geometry> > geoms) { this.techid = techid; this.passid = passid; this.UpdateTechnique(); //Rebuild Layout this.DisposeLayouts(); for (int i = 0; i < geoms.SliceCount; i++) { try { if (pass.Description.Signature != null) { InputLayout layout = new InputLayout(this.context.Device, pass.Description.Signature, geoms[i][this.context].InputLayout); this.layouts.Add(layout); this.layoutvalid.Add(true); this.layoutmsg.Add("OK"); } else { this.layouts.Add(null); this.layoutvalid.Add(true); this.layoutmsg.Add("OK"); } } catch { try { //Do bit of reflection work to get missing semantic EffectShaderVariable vs = pass.VertexShaderDescription.Variable; int inputcount = vs.GetShaderDescription(0).InputParameterCount; string missingsemantics = "Geometry is missing semantics: "; bool first = true; for (int vip = 0; vip < inputcount; vip++) { ShaderParameterDescription sd = vs.GetInputParameterDescription(0, vip); if (sd.SystemType == SystemValueType.Undefined) //Ignore SV semantics { bool found = false; foreach (InputElement e in geoms[i][this.context].InputLayout) { if (sd.SemanticName == e.SemanticName && sd.SemanticIndex == e.SemanticIndex) { found = true; } } if (!found) { string sem = sd.SemanticIndex == 0 ? "" : sd.SemanticIndex.ToString(); if (first) { first = false; } else { missingsemantics += " : "; } missingsemantics += sd.SemanticName + sem; } } } this.layouts.Add(null); this.layoutvalid.Add(false); this.layoutmsg.Add(missingsemantics); } catch (Exception ex) { //Just in case this.layouts.Add(null); this.layoutvalid.Add(false); this.layoutmsg.Add(ex.Message); } } } }
protected override List <CompilerError> VerifyShader(string file, DX11Effect effect) { List <CompilerError> errors = new List <CompilerError>(); if (effect.DefaultEffect.Description.TechniqueCount == 0) { errors.Add(new CompilerError(file, 0, 0, "", "Effect Has No techniques")); return(errors); } //Verify techniques for (int i = 0; i < effect.DefaultEffect.Description.TechniqueCount; i++) { EffectTechnique tech = effect.DefaultEffect.GetTechniqueByIndex(i); if (tech.Description.PassCount == 0) { errors.Add(new CompilerError(file, 0, 0, "", "Technique: " + tech.Description.Name + " has no passes")); return(errors); } else { for (int p = 0; p < tech.Description.PassCount; p++) { EffectPass pass = tech.GetPassByIndex(p); if (!this.ComputeOrPixelOnly(pass)) { errors.Add(new CompilerError(file, 0, 0, "", "Technique: " + tech.Description.Name + " : Pass : "******" Must be pixel only or compute only")); } else { //Manually validate layout for pixelshader if (this.PixelOnly(pass)) { EffectShaderVariable ps = pass.PixelShaderDescription.Variable; int inputcount = ps.GetShaderDescription(0).InputParameterCount; bool hassvpos = false; bool hasuv = false; for (int ip = 0; ip < inputcount; ip++) { ShaderParameterDescription sd = ps.GetInputParameterDescription(0, ip); if (sd.SystemType == SystemValueType.Position) { hassvpos = true; } if (sd.SemanticName == "TEXCOORD") { hasuv = true; } } if (!(hassvpos && hasuv) && inputcount == 2) { errors.Add(new CompilerError(file, 0, 0, "", "Technique: " + tech.Description.Name + " : Pass : "******" Must be SV_Position and TEXCOORD0 as input")); } } } } } } return(errors); }
private static void CompareParameter(ShaderParameterDescription expected, SignatureParameterDescription actual) { Assert.AreEqual((int) expected.ComponentType, (int) actual.ComponentType); //Assert.AreEqual((int) expected.ReadWriteMask, (int) actual.ReadWriteMask); // TODO: Bug in SharpDX? if (expected.Register != -1 || actual.Register != uint.MaxValue) Assert.AreEqual(expected.Register, actual.Register); Assert.AreEqual(expected.SemanticIndex, actual.SemanticIndex); Assert.AreEqual(expected.SemanticName, actual.SemanticName); Assert.AreEqual(expected.Stream, actual.Stream); Assert.AreEqual((int) expected.SystemValueType, (int) actual.SystemValueType); //Assert.AreEqual((int) expected.UsageMask, (int) actual.Mask); // TODO: Bug in SharpDX? }