Skip to content

Commit

Permalink
Try compiling shader from source if loading SPIR-V fails
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Oct 24, 2023
1 parent 67c6240 commit 0932c2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Dear ImGui for Godot Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<EmbeddedResource Remove="doc\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ImGui.NET" Version="1.89.9.1" />
<PackageReference Include="ImGui.NET" Version="1.89.9.2" />
</ItemGroup>
</Project>
28 changes: 11 additions & 17 deletions addons/imgui-godot/ImGuiGodot/Internal/RdRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,19 @@ public RdRenderer()
// compiling from source takes ~400ms, so we use a SPIR-V resource
using var spirv = ResourceLoader.Load<RDShaderSpirV>("res://addons/imgui-godot/data/ImGuiShaderSPIRV.tres");
_shader = RD.ShaderCreateFromSpirV(spirv);
if (!_shader.IsValid)
throw new RdRendererException("failed to create shader");

#if IMGUI_GODOT_DEV
#pragma warning disable CA2201
using var src = new RDShaderSource()
if (!_shader.IsValid)
{
SourceFragment = _fragmentShaderSource,
SourceVertex = _vertexShaderSource,
};
using var freshSpirv = RD.ShaderCompileSpirVFromSource(src);
if (!System.Linq.Enumerable.SequenceEqual(spirv.BytecodeFragment, freshSpirv.BytecodeFragment))
throw new Exception("fragment bytecode mismatch");
if (!System.Linq.Enumerable.SequenceEqual(spirv.BytecodeVertex, freshSpirv.BytecodeVertex))
throw new Exception("vertex bytecode mismatch");
#pragma warning restore CA2201
#endif
using var src = new RDShaderSource()
{
SourceFragment = _fragmentShaderSource,
SourceVertex = _vertexShaderSource,
};
using var freshSpirv = RD.ShaderCompileSpirVFromSource(src);
_shader = RD.ShaderCreateFromSpirV(freshSpirv);
if (!_shader.IsValid)
throw new RdRendererException("failed to create shader");
}

// create vertex format
uint vtxStride = (uint)Marshal.SizeOf<ImDrawVert>();
Expand Down Expand Up @@ -420,7 +416,6 @@ protected Rid GetFramebuffer(Rid vprid)
return fb;
}

#if IMGUI_GODOT_DEV
// shader source borrowed from imgui_impl_vulkan.cpp
private static readonly string _vertexShaderSource = @"#version 450 core
layout(location = 0) in vec2 aPos;
Expand All @@ -446,5 +441,4 @@ void main()
{
fColor = In.Color * texture(sTexture, In.UV.st);
}";
#endif
}

0 comments on commit 0932c2d

Please sign in to comment.