fix: CaptureFrame no longer overwrites CapturedFrame with null
Root cause: CaptureFrame returned null and was assigned to CapturedFrame, overwriting the data that ReadCapturedBuffer had just set at the start of the same frame. Fix: CaptureFrame is now void — only records GPU copy commands. ReadCapturedBuffer runs at start of next frame (after WaitFrame/fence) and sets CapturedFrame with actual pixel data. Program.cs reads CapturedFrame after RenderWorld — now contains data from the previous frame's GPU copy.
This commit is contained in:
Binary file not shown.
@@ -100,7 +100,7 @@ public sealed unsafe class VulkanRenderer : IRenderer, Engine.Graphics.IScreensh
|
|||||||
Vk.vkBindBufferMemory(_ctx.Device, _screenshotBuffer, _screenshotMemory, 0);
|
Vk.vkBindBufferMemory(_ctx.Device, _screenshotBuffer, _screenshotMemory, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[]? CaptureFrame(VkCommandBuffer cmd, uint imageIndex)
|
public void CaptureFrame(VkCommandBuffer cmd, uint imageIndex)
|
||||||
{
|
{
|
||||||
InitScreenshotBuffer();
|
InitScreenshotBuffer();
|
||||||
|
|
||||||
@@ -136,8 +136,6 @@ public sealed unsafe class VulkanRenderer : IRenderer, Engine.Graphics.IScreensh
|
|||||||
TransitionImageLayout(cmd, _swapchain.Images[imageIndex],
|
TransitionImageLayout(cmd, _swapchain.Images[imageIndex],
|
||||||
VkImageLayout.TransferSrcOptimal, VkImageLayout.ColorAttachmentOptimal,
|
VkImageLayout.TransferSrcOptimal, VkImageLayout.ColorAttachmentOptimal,
|
||||||
0x10000, 0x1000, 0x400, 0x100);
|
0x10000, 0x1000, 0x400, 0x100);
|
||||||
|
|
||||||
return null; // Data will be read next frame after GPU completes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[]? ReadCapturedBuffer()
|
private byte[]? ReadCapturedBuffer()
|
||||||
@@ -525,7 +523,7 @@ public sealed unsafe class VulkanRenderer : IRenderer, Engine.Graphics.IScreensh
|
|||||||
// Capture frame AFTER render pass ends, BEFORE present transition
|
// Capture frame AFTER render pass ends, BEFORE present transition
|
||||||
if (IsRecording)
|
if (IsRecording)
|
||||||
{
|
{
|
||||||
CapturedFrame = CaptureFrame(cmd, imageIndex);
|
CaptureFrame(cmd, imageIndex); // Only records GPU commands, does NOT overwrite CapturedFrame
|
||||||
}
|
}
|
||||||
|
|
||||||
TransitionImageLayout(cmd, _swapchain.Images[imageIndex],
|
TransitionImageLayout(cmd, _swapchain.Images[imageIndex],
|
||||||
|
|||||||
Reference in New Issue
Block a user