Astrobot - Vulkan fix (#733)

* log and vulkan fix

* Astrobot - Vulkan fix : OpControlBarrier
This commit is contained in:
Astell
2026-08-01 16:17:45 +02:00
committed by GitHub
parent c387b969e1
commit a8fa9c96dc
2 changed files with 67 additions and 21 deletions
@@ -4041,6 +4041,10 @@ internal static unsafe class VulkanVideoPresenter
"vkCreateDebugUtilsMessengerEXT"); "vkCreateDebugUtilsMessengerEXT");
} }
[ThreadStatic]
private static string? _pendingShaderModuleDumpPath;
private static unsafe uint DebugCallback( private static unsafe uint DebugCallback(
DebugUtilsMessageSeverityFlagsEXT severity, DebugUtilsMessageSeverityFlagsEXT severity,
DebugUtilsMessageTypeFlagsEXT type, DebugUtilsMessageTypeFlagsEXT type,
@@ -4055,6 +4059,24 @@ internal static unsafe class VulkanVideoPresenter
_ => "[VULKAN][INFO]", _ => "[VULKAN][INFO]",
}; };
Console.Error.WriteLine($"{prefix} {message}"); Console.Error.WriteLine($"{prefix} {message}");
if (severity == DebugUtilsMessageSeverityFlagsEXT.ErrorBitExt &&
message is not null &&
message.Contains("vkCreateShaderModule", StringComparison.Ordinal))
{
var dumpPath = _pendingShaderModuleDumpPath;
var dumpHint = dumpPath is null
? "Set SHARPEMU_SHADER_SPIRV_DUMP_DIR to a directory to "
+ "capture every module's .spv bytes for offline "
+ "spirv-dis/spirv-val analysis."
: $"Dumped module for this failure: {dumpPath}";
Console.Error.WriteLine(
"[SHARPEMU][ERROR] A guest shader compiled to invalid SPIR-V."
+ "The shader module was created without an API-level error. {dumpHint}");
}
return Vk.False; return Vk.False;
} }
private void CreateSurface() private void CreateSurface()
@@ -6844,7 +6866,25 @@ internal static unsafe class VulkanVideoPresenter
} }
} }
private static int _shaderModuleDumpSequence;
private ShaderModule CreateShaderModule(byte[] code) private ShaderModule CreateShaderModule(byte[] code)
{
string? dumpPath = null;
var dumpDirectory = Environment.GetEnvironmentVariable("SHARPEMU_SHADER_SPIRV_DUMP_DIR");
if (!string.IsNullOrWhiteSpace(dumpDirectory))
{
Directory.CreateDirectory(dumpDirectory);
var sequence = Interlocked.Increment(ref _shaderModuleDumpSequence);
dumpPath = Path.Combine(dumpDirectory, $"{sequence:D4}.spv");
File.WriteAllBytes(dumpPath, code);
_pendingShaderModuleDumpPath = dumpPath;
}
try
{ {
fixed (byte* codePointer = code) fixed (byte* codePointer = code)
{ {
@@ -6860,6 +6900,11 @@ internal static unsafe class VulkanVideoPresenter
return module; return module;
} }
} }
finally
{
_pendingShaderModuleDumpPath = null;
}
}
private TranslatedDrawResources CreateTranslatedDrawResources( private TranslatedDrawResources CreateTranslatedDrawResources(
VulkanTranslatedGuestDraw draw, VulkanTranslatedGuestDraw draw,
@@ -712,6 +712,8 @@ public static partial class Gen5SpirvTranslator
if (UsesSubgroupOperations()) if (UsesSubgroupOperations())
{ {
_module.AddCapability(SpirvCapability.GroupNonUniform); _module.AddCapability(SpirvCapability.GroupNonUniform);
_module.AddCapability(SpirvCapability.GroupNonUniformBallot);
if (UsesSubgroupShuffle()) if (UsesSubgroupShuffle())
{ {
_module.AddCapability(SpirvCapability.GroupNonUniformShuffle); _module.AddCapability(SpirvCapability.GroupNonUniformShuffle);
@@ -722,10 +724,6 @@ public static partial class Gen5SpirvTranslator
_module.AddCapability(SpirvCapability.GroupNonUniformVote); _module.AddCapability(SpirvCapability.GroupNonUniformVote);
} }
if (UsesSubgroupBroadcast() || UsesWaveControl())
{
_module.AddCapability(SpirvCapability.GroupNonUniformBallot);
}
} }
_glsl = _module.ImportExtInst("GLSL.std.450"); _glsl = _module.ImportExtInst("GLSL.std.450");
@@ -1802,6 +1800,8 @@ public static partial class Gen5SpirvTranslator
} }
if (instruction.Opcode == "SBarrier") if (instruction.Opcode == "SBarrier")
{
if (_stage == Gen5SpirvStage.Compute)
{ {
var workgroup = UInt(2); var workgroup = UInt(2);
var semantics = UInt(0x108); var semantics = UInt(0x108);
@@ -1810,6 +1810,7 @@ public static partial class Gen5SpirvTranslator
workgroup, workgroup,
workgroup, workgroup,
semantics); semantics);
}
return true; return true;
} }