Skip to content

Commit

Permalink
Issue #68: Eliminating dependency on D3DCompiler_43.dll.
Browse files Browse the repository at this point in the history
Originally for simplicity and faster iterations Optick GUI was compiling a couple of shaders on startup.
To avoid dependency on D3DCompiler_43.dll switching Optick to precompiled shaders.
  • Loading branch information
bombomby committed May 7, 2019
1 parent c683d98 commit 31d9f84
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 38 deletions.
37 changes: 14 additions & 23 deletions gui/DirectX/DirectXCanvas.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,25 @@ public Fragment LoadFragment(string fileName, InputElement[] inputElements)
{
Fragment result = new Fragment();

CompilationResult vertexShaderByteCode = null;
CompilationResult pixelShaderByteCode = null;
ShaderBytecode vertexShaderByteCode = null;
ShaderBytecode pixelShaderByteCode = null;

Assembly assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream("Profiler.DirectX." + fileName))
{
using (StreamReader reader = new StreamReader(stream))
{
//string data = reader.ReadToEnd();
byte[] data = new byte[stream.Length];
stream.Read(data, 0, data.Length);

vertexShaderByteCode = ShaderBytecode.Compile(data, "VS", "vs_4_0", ShaderFlags.None, EffectFlags.None);
pixelShaderByteCode = ShaderBytecode.Compile(data, "PS", "ps_4_0", ShaderFlags.None, EffectFlags.None);
}
using (Stream streamPS = assembly.GetManifestResourceStream("Profiler.DirectX.Shaders." + fileName + "_ps.fxo"))
{
pixelShaderByteCode = ShaderBytecode.FromStream(streamPS);
}

if (!String.IsNullOrEmpty(vertexShaderByteCode.Message))
Debug.WriteLine(vertexShaderByteCode.Message);

result.VS = new VertexShader(RenderDevice, vertexShaderByteCode);

if (!String.IsNullOrEmpty(pixelShaderByteCode.Message))
Debug.WriteLine(pixelShaderByteCode.Message);
using (Stream streamVS = assembly.GetManifestResourceStream("Profiler.DirectX.Shaders." + fileName + "_vs.fxo"))
{
vertexShaderByteCode = ShaderBytecode.FromStream(streamVS);
}

result.PS = new PixelShader(RenderDevice, pixelShaderByteCode);
result.VS = new VertexShader(RenderDevice, vertexShaderByteCode.Data);
result.PS = new PixelShader(RenderDevice, pixelShaderByteCode.Data);

result.Layout = new InputLayout(RenderDevice, ShaderSignature.GetInputSignature(vertexShaderByteCode), inputElements);
result.Layout = new InputLayout(RenderDevice, vertexShaderByteCode, inputElements);

vertexShaderByteCode.Dispose();
pixelShaderByteCode.Dispose();
Expand Down Expand Up @@ -161,13 +152,13 @@ public DirectXCanvas()

WPConstantBuffer = SharpDX.Direct3D11.Buffer.Create(RenderDevice, BindFlags.ConstantBuffer, ref WP);

DefaultFragment = LoadFragment(@"Basic.fx", new[]
DefaultFragment = LoadFragment(@"Basic", new[]
{
new InputElement("POSITION", 0, Format.R32G32_Float, 0, 0),
new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 8, 0)
});

TextFragment = LoadFragment(@"Text.fx", new[]
TextFragment = LoadFragment(@"Text", new[]
{
new InputElement("POSITION", 0, Format.R32G32_Float, 0, 0),
new InputElement("TEXCOORD", 0, Format.R32G32_Float, 8, 0),
Expand Down
File renamed without changes.
Binary file added gui/DirectX/Shaders/Basic_ps.fxo
Binary file not shown.
Binary file added gui/DirectX/Shaders/Basic_vs.fxo
Binary file not shown.
9 changes: 9 additions & 0 deletions gui/DirectX/Shaders/Compile.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Echo Building shaders
Echo Launch dir: "%~dp0"
Echo Current dir: "%CD%"
cd "%~dp0"
PATH="c:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Utilities\bin\x64\"
fxc.exe /T vs_4_0 /O3 /E VS /Fo Basic_vs.fxo Basic.fx
fxc.exe /T ps_4_0 /O3 /E PS /Fo Basic_ps.fxo Basic.fx
fxc.exe /T vs_4_0 /O3 /E VS /Fo Text_vs.fxo Text.fx
fxc.exe /T ps_4_0 /O3 /E PS /Fo Text_ps.fxo Text.fx
File renamed without changes.
Binary file added gui/DirectX/Shaders/Text_ps.fxo
Binary file not shown.
Binary file added gui/DirectX/Shaders/Text_vs.fxo
Binary file not shown.
6 changes: 0 additions & 6 deletions gui/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura>
<Unmanaged32Assemblies>
D3DCompiler_43
</Unmanaged32Assemblies>
<Unmanaged64Assemblies>
D3DCompiler_43
</Unmanaged64Assemblies>
</Costura>
</Weavers>
18 changes: 9 additions & 9 deletions gui/Optick.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@
<EmbeddedResource Include="DirectX\Fonts\SegoeUI_24_Normal.fnt" />
<EmbeddedResource Include="DirectX\Fonts\SegoeUI_32_Normal.fnt" />
<EmbeddedResource Include="DirectX\Fonts\SegoeUI_28_Normal.fnt" />
<EmbeddedResource Include="DirectX\Shaders\Basic_ps.fxo" />
<EmbeddedResource Include="DirectX\Shaders\Basic_vs.fxo" />
<EmbeddedResource Include="DirectX\Shaders\Text_ps.fxo" />
<EmbeddedResource Include="DirectX\Shaders\Text_vs.fxo" />
<None Include="DirectX\Shaders\Compile.bat" />
<None Include="packages.config" />
<AppDesigner Include="Properties\" />
<EmbeddedResource Include="TaskManager\brofiler-github-07994fd14248.p12" />
Expand Down Expand Up @@ -660,12 +665,6 @@
<ItemGroup>
<Resource Include="TimeLine\Icons\Clear-icon.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="DirectX\Basic.fx" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="DirectX\Text.fx" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="DirectX\Fonts\SegoeUI_16_Normal_0.png" />
</ItemGroup>
Expand All @@ -690,15 +689,16 @@
<ItemGroup>
<Resource Include="Resources\Bug.ico" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="costura64\D3DCompiler_43.dll" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\IDD\InteractiveDataDisplay.WPF\src\InteractiveDataDisplay.WPF.csproj">
<Project>{2d34544c-2df2-4b20-a43a-6c8d2df3dd82}</Project>
<Name>InteractiveDataDisplay.WPF</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="DirectX\Shaders\Basic.fx" />
<Content Include="DirectX\Shaders\Text.fx" />
</ItemGroup>
<Import Project="packages\Fody.4.0.2\build\Fody.targets" Condition="Exists('packages\Fody.4.0.2\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
Binary file removed gui/costura64/D3DCompiler_43.dll
Binary file not shown.

0 comments on commit 31d9f84

Please sign in to comment.