public void Check_ReadAndMergeFromAssemblyResources() { var resLink = new AssemblyResourceLink(this.GetType(), "Dummy", "CommonPixelShader.hlsl"); var singleShaderFileBuilder = new StringBuilder(1024); SingleShaderFileBuilder.ReadShaderFileAndResolveIncludes(resLink, singleShaderFileBuilder); var result = singleShaderFileBuilder.ToString(); Assert.IsTrue(result.Contains("constants.hlsl")); Assert.IsTrue(result.Contains("struct VSInputStandard")); Assert.IsTrue(result.Contains("float4 ApplyColorBorders(float4 inputColor, float distanceToCamera, float2 texCoord)")); }
private static byte[] GetShaderBytecode(EngineDevice device, ResourceLink resourceLink, ShaderResourceKind resourceKind, string shaderModel) { switch (resourceKind) { case ShaderResourceKind.Bytecode: using (var inStream = resourceLink.OpenInputStream()) { return(inStream.ReadAllBytes()); } case ShaderResourceKind.HlsFile: using (ReusableStringBuilders.Current.UseStringBuilder(out var singleShaderSourceBuilder, 10024)) { SingleShaderFileBuilder.ReadShaderFileAndResolveIncludes( resourceLink, singleShaderSourceBuilder); // device.DebugEnabled ? D3DCompiler.ShaderFlags.Debug : D3DCompiler.ShaderFlags.None var shaderSource = singleShaderSourceBuilder.ToString(); var compileResult = Compiler.Compile( shaderSource, Array.Empty <D3D.ShaderMacro>(), null !, "main", resourceLink.ToString() ?? "", shaderModel, device.DebugEnabled ? ShaderFlags.Debug : ShaderFlags.None, out var compBlob, out var compErrorBlob); try { if (compileResult.Failure) { throw new SeeingSharpGraphicsException($"Unable to compile shader from {resourceLink}: {compileResult.Code} - {compileResult.ToString()}"); } return(compBlob.GetBytes()); } finally { SeeingSharpUtil.SafeDispose(ref compBlob); SeeingSharpUtil.SafeDispose(ref compErrorBlob); } } default: throw new SeeingSharpException($"Unhandled {nameof(ShaderResourceKind)}: {resourceKind}"); } }