mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 14:18:31 +09:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9fa32bdad0 | ||
|
|
a4980f2b56 | ||
|
|
8ca20e28ca | ||
|
|
c353a2055f | ||
|
|
421c20984e |
@@ -16,18 +16,19 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
m_device = device;
|
m_device = device;
|
||||||
m_commandPool = commandPool;
|
m_commandPool = commandPool;
|
||||||
|
|
||||||
Vector<VkCommandBuffer> commandBuffers(frameCount, VK_NULL_HANDLE);
|
Vector<VkCommandBuffer> commandBuffers(frameCount * 2, VK_NULL_HANDLE);
|
||||||
VkCommandBufferAllocateInfo allocInfo{};
|
VkCommandBufferAllocateInfo allocInfo{};
|
||||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||||
allocInfo.commandPool = commandPool;
|
allocInfo.commandPool = commandPool;
|
||||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||||
allocInfo.commandBufferCount = frameCount;
|
allocInfo.commandBufferCount = frameCount * 2;
|
||||||
VkResult result = vkAllocateCommandBuffers(device, &allocInfo, commandBuffers.data());
|
VkResult result = vkAllocateCommandBuffers(device, &allocInfo, commandBuffers.data());
|
||||||
if (result != VK_SUCCESS) {
|
if (result != VK_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
for (Uint32 i = 0; i < frameCount; ++i) {
|
for (Uint32 i = 0; i < frameCount; ++i) {
|
||||||
m_frames[i].commandBuffer = commandBuffers[i];
|
m_frames[i].commandBuffer = commandBuffers[i];
|
||||||
|
m_frames[i].preCommandBuffer = commandBuffers[frameCount + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSemaphoreCreateInfo semaphoreInfo{VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO};
|
VkSemaphoreCreateInfo semaphoreInfo{VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO};
|
||||||
@@ -47,9 +48,10 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
|
|
||||||
void FrameContext::Destroy(VkDevice device, VkCommandPool commandPool) {
|
void FrameContext::Destroy(VkDevice device, VkCommandPool commandPool) {
|
||||||
const Uint32 frameCount = static_cast<Uint32>(m_frames.size());
|
const Uint32 frameCount = static_cast<Uint32>(m_frames.size());
|
||||||
Vector<VkCommandBuffer> commandBuffers(frameCount, VK_NULL_HANDLE);
|
Vector<VkCommandBuffer> commandBuffers(frameCount * 2, VK_NULL_HANDLE);
|
||||||
for (Uint32 i = 0; i < frameCount; ++i) {
|
for (Uint32 i = 0; i < frameCount; ++i) {
|
||||||
commandBuffers[i] = m_frames[i].commandBuffer;
|
commandBuffers[i] = m_frames[i].commandBuffer;
|
||||||
|
commandBuffers[frameCount + i] = m_frames[i].preCommandBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Uint32 i = 0; i < frameCount; ++i) {
|
for (Uint32 i = 0; i < frameCount; ++i) {
|
||||||
@@ -60,7 +62,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
for (auto& frame : m_frames) {
|
for (auto& frame : m_frames) {
|
||||||
FreeRetiredCommandBuffers(frame);
|
FreeRetiredCommandBuffers(frame);
|
||||||
}
|
}
|
||||||
vkFreeCommandBuffers(device, commandPool, frameCount, commandBuffers.data());
|
vkFreeCommandBuffers(device, commandPool, frameCount * 2, commandBuffers.data());
|
||||||
}
|
}
|
||||||
m_frames.clear();
|
m_frames.clear();
|
||||||
currentFrameIndex = 0;
|
currentFrameIndex = 0;
|
||||||
@@ -87,6 +89,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
currentFrameIndex = (currentFrameIndex + 1) % static_cast<Uint32>(m_frames.size());
|
currentFrameIndex = (currentFrameIndex + 1) % static_cast<Uint32>(m_frames.size());
|
||||||
GetCurrent().isCommandRecording = false;
|
GetCurrent().isCommandRecording = false;
|
||||||
GetCurrent().hasCommandBufferRecorded = false;
|
GetCurrent().hasCommandBufferRecorded = false;
|
||||||
|
GetCurrent().isPreCommandRecording = false;
|
||||||
|
GetCurrent().hasPreCommandBufferRecorded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkCommandBuffer& FrameContext::BeginCommandRecording(VkCommandBufferUsageFlags flags,
|
VkCommandBuffer& FrameContext::BeginCommandRecording(VkCommandBufferUsageFlags flags,
|
||||||
@@ -118,6 +122,41 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
frame.hasCommandBufferRecorded = true;
|
frame.hasCommandBufferRecorded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkCommandBuffer FrameContext::BeginPreCommandRecording() {
|
||||||
|
auto& frame = GetCurrent();
|
||||||
|
if (frame.isPreCommandRecording) {
|
||||||
|
return frame.preCommandBuffer;
|
||||||
|
}
|
||||||
|
MOBILEGL_ASSERT(!frame.hasPreCommandBufferRecorded,
|
||||||
|
"BeginPreCommandRecording: a recorded pre stream is still awaiting submission");
|
||||||
|
VK_VERIFY(vkResetCommandBuffer(frame.preCommandBuffer, 0), "BeginPreCommandRecording, vkResetCommandBuffer");
|
||||||
|
VkCommandBufferBeginInfo beginInfo{};
|
||||||
|
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||||
|
VK_VERIFY(vkBeginCommandBuffer(frame.preCommandBuffer, &beginInfo),
|
||||||
|
"BeginPreCommandRecording, vkBeginCommandBuffer");
|
||||||
|
frame.isPreCommandRecording = true;
|
||||||
|
return frame.preCommandBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FrameContext::EndPreCommandRecordingIfOpen() {
|
||||||
|
auto& frame = GetCurrent();
|
||||||
|
if (!frame.isPreCommandRecording) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
VK_VERIFY(vkEndCommandBuffer(frame.preCommandBuffer), "EndPreCommandRecordingIfOpen, vkEndCommandBuffer");
|
||||||
|
frame.isPreCommandRecording = false;
|
||||||
|
frame.hasPreCommandBufferRecorded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FrameContext::AbandonPreCommandRecording() {
|
||||||
|
auto& frame = GetCurrent();
|
||||||
|
if (frame.isPreCommandRecording) {
|
||||||
|
VK_VERIFY(vkEndCommandBuffer(frame.preCommandBuffer), "AbandonPreCommandRecording, vkEndCommandBuffer");
|
||||||
|
}
|
||||||
|
frame.isPreCommandRecording = false;
|
||||||
|
frame.hasPreCommandBufferRecorded = false;
|
||||||
|
}
|
||||||
|
|
||||||
VkResult FrameContext::InitializeSwapchainSemaphores(VkDevice device, Uint32 swapchainImageCount) {
|
VkResult FrameContext::InitializeSwapchainSemaphores(VkDevice device, Uint32 swapchainImageCount) {
|
||||||
DestroySwapchainSemaphores(device);
|
DestroySwapchainSemaphores(device);
|
||||||
if (swapchainImageCount == 0) {
|
if (swapchainImageCount == 0) {
|
||||||
@@ -202,17 +241,27 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
Uint32 swapchainImageIndex) const {
|
Uint32 swapchainImageIndex) const {
|
||||||
const auto& frame = GetCurrent();
|
const auto& frame = GetCurrent();
|
||||||
MOBILEGL_ASSERT(!frame.isCommandRecording, "GetSubmitInfo called while command buffer recording is still active");
|
MOBILEGL_ASSERT(!frame.isCommandRecording, "GetSubmitInfo called while command buffer recording is still active");
|
||||||
|
MOBILEGL_ASSERT(!frame.isPreCommandRecording,
|
||||||
|
"GetSubmitInfo called while the pre-pass stream is still recording");
|
||||||
AssertValidSwapchainImageIndex(swapchainImageIndex);
|
AssertValidSwapchainImageIndex(swapchainImageIndex);
|
||||||
SubmitInfoPacket packet{};
|
SubmitInfoPacket packet{};
|
||||||
packet.waitSemaphore = frame.imageAvailableSemaphore;
|
packet.waitSemaphore = frame.imageAvailableSemaphore;
|
||||||
packet.signalSemaphore = m_swapchainImageRenderFinishedSemaphores[swapchainImageIndex];
|
packet.signalSemaphore = m_swapchainImageRenderFinishedSemaphores[swapchainImageIndex];
|
||||||
packet.commandBuffer = frame.commandBuffer;
|
|
||||||
|
Uint32 commandBufferCount = 0;
|
||||||
|
// The pre-pass stream executes strictly before the frame's commands.
|
||||||
|
if (frame.hasPreCommandBufferRecorded) {
|
||||||
|
packet.commandBuffers[commandBufferCount++] = frame.preCommandBuffer;
|
||||||
|
}
|
||||||
|
if (shouldSubmitCommandBuffer) {
|
||||||
|
packet.commandBuffers[commandBufferCount++] = frame.commandBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
packet.submitInfo.waitSemaphoreCount = frame.imageAvailableSemaphoreConsumed ? 0U : 1U;
|
packet.submitInfo.waitSemaphoreCount = frame.imageAvailableSemaphoreConsumed ? 0U : 1U;
|
||||||
packet.submitInfo.pWaitSemaphores = frame.imageAvailableSemaphoreConsumed ? nullptr : &packet.waitSemaphore;
|
packet.submitInfo.pWaitSemaphores = frame.imageAvailableSemaphoreConsumed ? nullptr : &packet.waitSemaphore;
|
||||||
packet.submitInfo.pWaitDstStageMask = frame.imageAvailableSemaphoreConsumed ? nullptr : &packet.waitDstStageMask;
|
packet.submitInfo.pWaitDstStageMask = frame.imageAvailableSemaphoreConsumed ? nullptr : &packet.waitDstStageMask;
|
||||||
packet.submitInfo.commandBufferCount = shouldSubmitCommandBuffer ? 1U : 0U;
|
packet.submitInfo.commandBufferCount = commandBufferCount;
|
||||||
packet.submitInfo.pCommandBuffers = shouldSubmitCommandBuffer ? &packet.commandBuffer : nullptr;
|
packet.submitInfo.pCommandBuffers = commandBufferCount > 0 ? packet.commandBuffers : nullptr;
|
||||||
packet.submitInfo.signalSemaphoreCount = 1;
|
packet.submitInfo.signalSemaphoreCount = 1;
|
||||||
packet.submitInfo.pSignalSemaphores = &packet.signalSemaphore;
|
packet.submitInfo.pSignalSemaphores = &packet.signalSemaphore;
|
||||||
return packet;
|
return packet;
|
||||||
@@ -276,12 +325,14 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
m_recordingObserver = observer;
|
m_recordingObserver = observer;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkResult FrameContext::RetireCurrentCommandBuffer() {
|
VkResult FrameContext::RetireCurrentCommandBuffer(Bool retirePreCommandBuffer) {
|
||||||
MOBILEGL_ASSERT(m_device != VK_NULL_HANDLE && m_commandPool != VK_NULL_HANDLE,
|
MOBILEGL_ASSERT(m_device != VK_NULL_HANDLE && m_commandPool != VK_NULL_HANDLE,
|
||||||
"RetireCurrentCommandBuffer requires an initialized FrameContext");
|
"RetireCurrentCommandBuffer requires an initialized FrameContext");
|
||||||
auto& frame = GetCurrent();
|
auto& frame = GetCurrent();
|
||||||
MOBILEGL_ASSERT(!frame.isCommandRecording,
|
MOBILEGL_ASSERT(!frame.isCommandRecording,
|
||||||
"RetireCurrentCommandBuffer called while the command buffer is still recording");
|
"RetireCurrentCommandBuffer called while the command buffer is still recording");
|
||||||
|
MOBILEGL_ASSERT(!frame.isPreCommandRecording,
|
||||||
|
"RetireCurrentCommandBuffer called while the pre-pass stream is still recording");
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo allocInfo{};
|
VkCommandBufferAllocateInfo allocInfo{};
|
||||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||||
@@ -289,10 +340,20 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||||
allocInfo.commandBufferCount = 1;
|
allocInfo.commandBufferCount = 1;
|
||||||
VkCommandBuffer replacement = VK_NULL_HANDLE;
|
VkCommandBuffer replacement = VK_NULL_HANDLE;
|
||||||
const VkResult result = vkAllocateCommandBuffers(m_device, &allocInfo, &replacement);
|
VkResult result = vkAllocateCommandBuffers(m_device, &allocInfo, &replacement);
|
||||||
if (result != VK_SUCCESS) {
|
if (result != VK_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
if (retirePreCommandBuffer) {
|
||||||
|
VkCommandBuffer preReplacement = VK_NULL_HANDLE;
|
||||||
|
result = vkAllocateCommandBuffers(m_device, &allocInfo, &preReplacement);
|
||||||
|
if (result != VK_SUCCESS) {
|
||||||
|
vkFreeCommandBuffers(m_device, m_commandPool, 1, &replacement);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
frame.retiredCommandBuffers.push_back({frame.preCommandBuffer, frame.lastSubmitIndex});
|
||||||
|
frame.preCommandBuffer = preReplacement;
|
||||||
|
}
|
||||||
// lastSubmitIndex was just written by the renderer for the submission
|
// lastSubmitIndex was just written by the renderer for the submission
|
||||||
// that carried this command buffer.
|
// that carried this command buffer.
|
||||||
frame.retiredCommandBuffers.push_back({frame.commandBuffer, frame.lastSubmitIndex});
|
frame.retiredCommandBuffers.push_back({frame.commandBuffer, frame.lastSubmitIndex});
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
VkPipelineStageFlags waitDstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
VkPipelineStageFlags waitDstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||||
VkSemaphore waitSemaphore = VK_NULL_HANDLE;
|
VkSemaphore waitSemaphore = VK_NULL_HANDLE;
|
||||||
VkSemaphore signalSemaphore = VK_NULL_HANDLE;
|
VkSemaphore signalSemaphore = VK_NULL_HANDLE;
|
||||||
VkCommandBuffer commandBuffer = VK_NULL_HANDLE;
|
// [0] = pre-pass command buffer (when recorded), then the frame
|
||||||
|
// command buffer; submitInfo.pCommandBuffers points here.
|
||||||
|
VkCommandBuffer commandBuffers[2] = {VK_NULL_HANDLE, VK_NULL_HANDLE};
|
||||||
VkSubmitInfo submitInfo{VK_STRUCTURE_TYPE_SUBMIT_INFO};
|
VkSubmitInfo submitInfo{VK_STRUCTURE_TYPE_SUBMIT_INFO};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -52,10 +54,18 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
|
|
||||||
struct FrameData {
|
struct FrameData {
|
||||||
VkCommandBuffer commandBuffer = VK_NULL_HANDLE;
|
VkCommandBuffer commandBuffer = VK_NULL_HANDLE;
|
||||||
|
// Pre-pass work stream: out-of-pass commands (deferred clear
|
||||||
|
// materialization, sampled-layout transitions) for resources the
|
||||||
|
// frame's recording has not touched yet. Submitted immediately
|
||||||
|
// BEFORE commandBuffer in the same vkQueueSubmit, so recording
|
||||||
|
// into it never has to split the frame's active render pass.
|
||||||
|
VkCommandBuffer preCommandBuffer = VK_NULL_HANDLE;
|
||||||
VkSemaphore imageAvailableSemaphore = VK_NULL_HANDLE;
|
VkSemaphore imageAvailableSemaphore = VK_NULL_HANDLE;
|
||||||
VkFence imageInFlightFence = VK_NULL_HANDLE;
|
VkFence imageInFlightFence = VK_NULL_HANDLE;
|
||||||
Bool isCommandRecording = false;
|
Bool isCommandRecording = false;
|
||||||
Bool hasCommandBufferRecorded = false;
|
Bool hasCommandBufferRecorded = false;
|
||||||
|
Bool isPreCommandRecording = false;
|
||||||
|
Bool hasPreCommandBufferRecorded = false;
|
||||||
Bool imageAvailableSemaphoreConsumed = false;
|
Bool imageAvailableSemaphoreConsumed = false;
|
||||||
// Command buffers submitted mid-frame (FlushPendingCommands),
|
// Command buffers submitted mid-frame (FlushPendingCommands),
|
||||||
// appended in submit order; freed once their submission is known
|
// appended in submit order; freed once their submission is known
|
||||||
@@ -77,6 +87,14 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
VkCommandBuffer& BeginCommandRecording(VkCommandBufferUsageFlags flags = 0,
|
VkCommandBuffer& BeginCommandRecording(VkCommandBufferUsageFlags flags = 0,
|
||||||
const VkCommandBufferInheritanceInfo* pInheritanceInfo = nullptr);
|
const VkCommandBufferInheritanceInfo* pInheritanceInfo = nullptr);
|
||||||
void EndCommandRecording();
|
void EndCommandRecording();
|
||||||
|
// Lazily opens the pre-pass work stream (see FrameData::preCommandBuffer).
|
||||||
|
VkCommandBuffer BeginPreCommandRecording();
|
||||||
|
// Closes the pre stream if open, marking it for submission ahead of the
|
||||||
|
// frame command buffer. Safe to call when it never opened.
|
||||||
|
void EndPreCommandRecordingIfOpen();
|
||||||
|
// Drops an in-progress or recorded-but-unsubmitted pre stream (dropped
|
||||||
|
// frame recordings, swapchain recreation).
|
||||||
|
void AbandonPreCommandRecording();
|
||||||
VkResult InitializeSwapchainSemaphores(VkDevice device, Uint32 swapchainImageCount);
|
VkResult InitializeSwapchainSemaphores(VkDevice device, Uint32 swapchainImageCount);
|
||||||
void DestroySwapchainSemaphores(VkDevice device);
|
void DestroySwapchainSemaphores(VkDevice device);
|
||||||
Bool TransitionToPresent(VkImage image, VkImageLayout oldLayout,
|
Bool TransitionToPresent(VkImage image, VkImageLayout oldLayout,
|
||||||
@@ -91,7 +109,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
// can restart while the submitted buffer is still executing. Retired
|
// can restart while the submitted buffer is still executing. Retired
|
||||||
// buffers are freed after the slot's fence is next waited, or as soon
|
// buffers are freed after the slot's fence is next waited, or as soon
|
||||||
// as their submission is observed complete.
|
// as their submission is observed complete.
|
||||||
VkResult RetireCurrentCommandBuffer();
|
VkResult RetireCurrentCommandBuffer(Bool retirePreCommandBuffer = false);
|
||||||
|
|
||||||
// Frees every retired command buffer whose tagged submission index is
|
// Frees every retired command buffer whose tagged submission index is
|
||||||
// known complete. Driven by the renderer's submit tracker on completion
|
// known complete. Driven by the renderer's submit tracker on completion
|
||||||
|
|||||||
@@ -262,6 +262,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
m_images.resize(imageCount, VK_NULL_HANDLE);
|
m_images.resize(imageCount, VK_NULL_HANDLE);
|
||||||
VK_VERIFY(vkGetSwapchainImagesKHR(device, m_swapchain, &imageCount, m_images.data()));
|
VK_VERIFY(vkGetSwapchainImagesKHR(device, m_swapchain, &imageCount, m_images.data()));
|
||||||
m_imageLayouts.assign(imageCount, VK_IMAGE_LAYOUT_UNDEFINED);
|
m_imageLayouts.assign(imageCount, VK_IMAGE_LAYOUT_UNDEFINED);
|
||||||
|
// Fresh swapchain images hold garbage until a render pass stores into them.
|
||||||
|
m_imageContentDefined.assign(imageCount, false);
|
||||||
|
m_depthStencilContentDefined.assign(imageCount, false);
|
||||||
|
|
||||||
CreateImageViews(device);
|
CreateImageViews(device);
|
||||||
CreateDepthStencilResources(device, physicalDevice);
|
CreateDepthStencilResources(device, physicalDevice);
|
||||||
@@ -433,9 +436,39 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
|
|
||||||
m_images.clear();
|
m_images.clear();
|
||||||
m_imageLayouts.clear();
|
m_imageLayouts.clear();
|
||||||
|
m_imageContentDefined.clear();
|
||||||
|
m_depthStencilContentDefined.clear();
|
||||||
m_preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
m_preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bool SwapchainObject::IsImageContentDefined(Uint32 index) const {
|
||||||
|
MOBILEGL_ASSERT(index < m_imageContentDefined.size(), "Swapchain image content index out of range");
|
||||||
|
return m_imageContentDefined[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwapchainObject::SetImageContentDefined(Uint32 index, Bool defined) {
|
||||||
|
MOBILEGL_ASSERT(index < m_imageContentDefined.size(), "Swapchain image content index out of range");
|
||||||
|
m_imageContentDefined[index] = defined;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bool SwapchainObject::IsDepthStencilContentDefined(Uint32 index) const {
|
||||||
|
MOBILEGL_ASSERT(index < m_depthStencilContentDefined.size(),
|
||||||
|
"Swapchain depth/stencil content index out of range");
|
||||||
|
return m_depthStencilContentDefined[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwapchainObject::SetDepthStencilContentDefined(Uint32 index, Bool defined) {
|
||||||
|
MOBILEGL_ASSERT(index < m_depthStencilContentDefined.size(),
|
||||||
|
"Swapchain depth/stencil content index out of range");
|
||||||
|
m_depthStencilContentDefined[index] = defined;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwapchainObject::SetAllDepthStencilContentUndefined() {
|
||||||
|
for (SizeT i = 0; i < m_depthStencilContentDefined.size(); ++i) {
|
||||||
|
m_depthStencilContentDefined[i] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
VkImage SwapchainObject::GetImage(Uint32 index) const {
|
VkImage SwapchainObject::GetImage(Uint32 index) const {
|
||||||
MOBILEGL_ASSERT(index < m_images.size(), "Swapchain image index out of range");
|
MOBILEGL_ASSERT(index < m_images.size(), "Swapchain image index out of range");
|
||||||
return m_images[index];
|
return m_images[index];
|
||||||
|
|||||||
@@ -52,6 +52,21 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
void SetImageLayout(Uint32 index, VkImageLayout layout);
|
void SetImageLayout(Uint32 index, VkImageLayout layout);
|
||||||
SizeT GetImageCount() const { return m_images.size(); }
|
SizeT GetImageCount() const { return m_images.size(); }
|
||||||
|
|
||||||
|
// EGL content-validity tracking for the default framebuffer. A color
|
||||||
|
// buffer's content is undefined once its image has been presented
|
||||||
|
// (EGL_BUFFER_DESTROYED swap behaviour, the implementation default),
|
||||||
|
// and every ancillary (depth/stencil) buffer's content is undefined
|
||||||
|
// after ANY swap regardless of swap behaviour (EGL 1.5 §3.10.1). The
|
||||||
|
// render-pass manager turns an undefined attachment's tile load into
|
||||||
|
// LOAD_OP_DONT_CARE. Flags start false (a fresh swapchain image holds
|
||||||
|
// garbage) and a render pass storing into an attachment sets it back
|
||||||
|
// to defined.
|
||||||
|
Bool IsImageContentDefined(Uint32 index) const;
|
||||||
|
void SetImageContentDefined(Uint32 index, Bool defined);
|
||||||
|
Bool IsDepthStencilContentDefined(Uint32 index) const;
|
||||||
|
void SetDepthStencilContentDefined(Uint32 index, Bool defined);
|
||||||
|
void SetAllDepthStencilContentUndefined();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void CreateImageViews(VkDevice device);
|
void CreateImageViews(VkDevice device);
|
||||||
void CreateDepthStencilResources(VkDevice device, VkPhysicalDevice physicalDevice);
|
void CreateDepthStencilResources(VkDevice device, VkPhysicalDevice physicalDevice);
|
||||||
@@ -77,5 +92,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
Vector<VkDeviceMemory> m_depthStencilImageMemories;
|
Vector<VkDeviceMemory> m_depthStencilImageMemories;
|
||||||
Vector<VkImageView> m_depthStencilImageViews;
|
Vector<VkImageView> m_depthStencilImageViews;
|
||||||
Vector<VkImageLayout> m_depthStencilImageLayouts;
|
Vector<VkImageLayout> m_depthStencilImageLayouts;
|
||||||
|
Vector<Bool> m_imageContentDefined;
|
||||||
|
Vector<Bool> m_depthStencilContentDefined;
|
||||||
};
|
};
|
||||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||||
|
|||||||
@@ -481,7 +481,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VkRenderPassManager::HashType VkRenderPassManager::ComputeHash(
|
VkRenderPassManager::HashType VkRenderPassManager::ComputeHash(
|
||||||
const MG_State::GLState::FramebufferObject& fbo, Uint32 swapchainImageIndex, Bool includePendingClear) {
|
const MG_State::GLState::FramebufferObject& fbo, Uint32 swapchainImageIndex, Bool includePendingClear,
|
||||||
|
Bool includeDefaultFboDepthStencil) {
|
||||||
XXHASH_VERIFY(XXH64_reset(m_hashState, m_config.CacheVersion));
|
XXHASH_VERIFY(XXH64_reset(m_hashState, m_config.CacheVersion));
|
||||||
const Bool isDefaultFbo = fbo.IsDefaultFramebuffer();
|
const Bool isDefaultFbo = fbo.IsDefaultFramebuffer();
|
||||||
if (isDefaultFbo) {
|
if (isDefaultFbo) {
|
||||||
@@ -560,9 +561,17 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
attachment <= FramebufferAttachmentType::BackRight);
|
attachment <= FramebufferAttachmentType::BackRight);
|
||||||
if (isDefaultColorAttachment) {
|
if (isDefaultColorAttachment) {
|
||||||
currentLayout = m_swapchainObject.GetImageLayout(swapchainImageIndex);
|
currentLayout = m_swapchainObject.GetImageLayout(swapchainImageIndex);
|
||||||
|
// Content validity feeds the attachment's loadOp (see the
|
||||||
|
// creation path), so it must key the cache as well.
|
||||||
|
if (!m_swapchainObject.IsImageContentDefined(swapchainImageIndex)) {
|
||||||
|
currentLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
}
|
||||||
} else if (attachment == FramebufferAttachmentType::Depth ||
|
} else if (attachment == FramebufferAttachmentType::Depth ||
|
||||||
attachment == FramebufferAttachmentType::Stencil) {
|
attachment == FramebufferAttachmentType::Stencil) {
|
||||||
currentLayout = m_swapchainObject.GetDepthStencilImageLayout(swapchainImageIndex);
|
currentLayout = m_swapchainObject.GetDepthStencilImageLayout(swapchainImageIndex);
|
||||||
|
if (!m_swapchainObject.IsDepthStencilContentDefined(swapchainImageIndex)) {
|
||||||
|
currentLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto* textureResource = m_textureManager.SyncTextureAndGetDescriptor(*texture);
|
auto* textureResource = m_textureManager.SyncTextureAndGetDescriptor(*texture);
|
||||||
@@ -617,14 +626,49 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
combineFramebufferAttachmentObjHash(drawbuf);
|
combineFramebufferAttachmentObjHash(drawbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The depth-less default-FBO flavor omits the depth/stencil attachment
|
||||||
|
// entirely, so it must hash differently from the depth-full flavor.
|
||||||
|
const Bool depthStencilIncluded = !isDefaultFbo || includeDefaultFboDepthStencil;
|
||||||
|
XXHASH_VERIFY(XXH64_update(m_hashState, &depthStencilIncluded, sizeof(depthStencilIncluded)));
|
||||||
|
if (depthStencilIncluded) {
|
||||||
combineFramebufferAttachmentObjHash(FramebufferAttachmentType::Depth);
|
combineFramebufferAttachmentObjHash(FramebufferAttachmentType::Depth);
|
||||||
combineFramebufferAttachmentObjHash(FramebufferAttachmentType::Stencil);
|
combineFramebufferAttachmentObjHash(FramebufferAttachmentType::Stencil);
|
||||||
|
}
|
||||||
|
|
||||||
return XXH64_digest(m_hashState);
|
return XXH64_digest(m_hashState);
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderPassEntry& VkRenderPassManager::GetOrCreateRenderPass(const MG_State::GLState::FramebufferObject& fbo,
|
RenderPassEntry& VkRenderPassManager::GetOrCreateRenderPass(const MG_State::GLState::FramebufferObject& fbo,
|
||||||
Uint32 swapchainImageIndex) {
|
Uint32 swapchainImageIndex,
|
||||||
|
Bool drawUsesDepthStencil) {
|
||||||
|
// Resolve the default-FBO depth flavor (see the header comment): keep the
|
||||||
|
// depth attachment when the caller needs it, when a depth/stencil clear is
|
||||||
|
// pending, or when the active pass already carries it (escalate-only, so
|
||||||
|
// alternating depth-less draws never split an established depth pass).
|
||||||
|
Bool includeDefaultFboDepthStencil = true;
|
||||||
|
if (fbo.IsDefaultFramebuffer()) {
|
||||||
|
Bool activeDefaultHasDepthStencil = false;
|
||||||
|
if (const auto* active = GetActiveRenderPass()) {
|
||||||
|
Bool activeIsSwapchainPass = false;
|
||||||
|
Bool activeHasSwapchainDepthStencil = false;
|
||||||
|
for (const auto& tracked : active->trackedAttachmentLayouts) {
|
||||||
|
activeIsSwapchainPass |= tracked.target == TrackedAttachmentTarget::SwapchainColor;
|
||||||
|
activeHasSwapchainDepthStencil |=
|
||||||
|
tracked.target == TrackedAttachmentTarget::SwapchainDepthStencil;
|
||||||
|
}
|
||||||
|
activeDefaultHasDepthStencil = activeIsSwapchainPass && activeHasSwapchainDepthStencil;
|
||||||
|
}
|
||||||
|
const auto& defaultDepthAtt = fbo.GetAttachment(FramebufferAttachmentType::Depth);
|
||||||
|
const auto& defaultStencilAtt = fbo.GetAttachment(FramebufferAttachmentType::Stencil);
|
||||||
|
const Bool pendingDepthStencilClear =
|
||||||
|
(defaultDepthAtt.IsTexture() && m_clearManager.HasPendingClear(defaultDepthAtt)) ||
|
||||||
|
HasPendingRenderbufferClear(defaultDepthAtt) ||
|
||||||
|
(defaultStencilAtt.IsTexture() && m_clearManager.HasPendingClear(defaultStencilAtt)) ||
|
||||||
|
HasPendingRenderbufferClear(defaultStencilAtt);
|
||||||
|
includeDefaultFboDepthStencil =
|
||||||
|
drawUsesDepthStencil || activeDefaultHasDepthStencil || pendingDepthStencilClear;
|
||||||
|
}
|
||||||
|
|
||||||
auto hasPendingClearOnFramebuffer = [&]() -> Bool {
|
auto hasPendingClearOnFramebuffer = [&]() -> Bool {
|
||||||
const auto& drawBuffers = fbo.GetDrawBuffers();
|
const auto& drawBuffers = fbo.GetDrawBuffers();
|
||||||
for (auto attachment : drawBuffers) {
|
for (auto attachment : drawBuffers) {
|
||||||
@@ -674,6 +718,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
m_rpFastFboVersion == fbo.GetObjectVersion() && m_rpFastSwapchainIndex == swapchainImageIndex &&
|
m_rpFastFboVersion == fbo.GetObjectVersion() && m_rpFastSwapchainIndex == swapchainImageIndex &&
|
||||||
m_rpFastTexEpoch == m_textureManager.GetTextureImageEpoch() &&
|
m_rpFastTexEpoch == m_textureManager.GetTextureImageEpoch() &&
|
||||||
m_rpFastRbEpoch == m_renderbufferImageEpoch &&
|
m_rpFastRbEpoch == m_renderbufferImageEpoch &&
|
||||||
|
(!fbo.IsDefaultFramebuffer() || m_rpFastHadDepthStencil == includeDefaultFboDepthStencil) &&
|
||||||
m_rpFastRenderPassHash == activeRenderPass->hash && !hasPendingClearOnFramebuffer()) {
|
m_rpFastRenderPassHash == activeRenderPass->hash && !hasPendingClearOnFramebuffer()) {
|
||||||
auto activeIt = m_renderPasses.find(activeRenderPass->hash);
|
auto activeIt = m_renderPasses.find(activeRenderPass->hash);
|
||||||
if (activeIt != m_renderPasses.end()) {
|
if (activeIt != m_renderPasses.end()) {
|
||||||
@@ -682,7 +727,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto compatibilityHash = ComputeHash(fbo, swapchainImageIndex, false);
|
auto compatibilityHash = ComputeHash(fbo, swapchainImageIndex, false, includeDefaultFboDepthStencil);
|
||||||
if (activeRenderPass != nullptr &&
|
if (activeRenderPass != nullptr &&
|
||||||
activeRenderPass->CompatibleWith(compatibilityHash) &&
|
activeRenderPass->CompatibleWith(compatibilityHash) &&
|
||||||
!hasPendingClearOnFramebuffer()) {
|
!hasPendingClearOnFramebuffer()) {
|
||||||
@@ -699,10 +744,11 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
m_rpFastTexEpoch = m_textureManager.GetTextureImageEpoch();
|
m_rpFastTexEpoch = m_textureManager.GetTextureImageEpoch();
|
||||||
m_rpFastRbEpoch = m_renderbufferImageEpoch;
|
m_rpFastRbEpoch = m_renderbufferImageEpoch;
|
||||||
m_rpFastRenderPassHash = activeRenderPass->hash;
|
m_rpFastRenderPassHash = activeRenderPass->hash;
|
||||||
|
m_rpFastHadDepthStencil = activeIt->second.hasDepthStencilAttachment;
|
||||||
activeIt->second.lastUsedFrame = m_frameCounter;
|
activeIt->second.lastUsedFrame = m_frameCounter;
|
||||||
return activeIt->second;
|
return activeIt->second;
|
||||||
}
|
}
|
||||||
auto hash = ComputeHash(fbo, swapchainImageIndex, true);
|
auto hash = ComputeHash(fbo, swapchainImageIndex, true, includeDefaultFboDepthStencil);
|
||||||
auto it = m_renderPasses.find(hash);
|
auto it = m_renderPasses.find(hash);
|
||||||
if (it != m_renderPasses.end()) {
|
if (it != m_renderPasses.end()) {
|
||||||
it->second.lastUsedFrame = m_frameCounter;
|
it->second.lastUsedFrame = m_frameCounter;
|
||||||
@@ -894,6 +940,13 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
MOBILEGL_ASSERT(swapchainImageIndex < swapchainViews.size(),
|
MOBILEGL_ASSERT(swapchainImageIndex < swapchainViews.size(),
|
||||||
"GetOrCreateRenderPass: swapchain image index out of range");
|
"GetOrCreateRenderPass: swapchain image index out of range");
|
||||||
trackedColorLayout = m_swapchainObject.GetImageLayout(swapchainImageIndex);
|
trackedColorLayout = m_swapchainObject.GetImageLayout(swapchainImageIndex);
|
||||||
|
// EGL: a presented color buffer's content is undefined when its
|
||||||
|
// image comes back around (EGL_BUFFER_DESTROYED, the default
|
||||||
|
// swap behaviour) - skip the tile load instead of reloading
|
||||||
|
// stale pixels nobody may rely on.
|
||||||
|
if (!hasClear && !m_swapchainObject.IsImageContentDefined(swapchainImageIndex)) {
|
||||||
|
trackedColorLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
}
|
||||||
trackedAttachmentLayouts.emplace_back(TrackedAttachmentLayoutInfo {
|
trackedAttachmentLayouts.emplace_back(TrackedAttachmentLayoutInfo {
|
||||||
.target = TrackedAttachmentTarget::SwapchainColor,
|
.target = TrackedAttachmentTarget::SwapchainColor,
|
||||||
.swapchainImageIndex = swapchainImageIndex,
|
.swapchainImageIndex = swapchainImageIndex,
|
||||||
@@ -976,6 +1029,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
};
|
};
|
||||||
const auto* selectedDepthStencilAttachment = isUsableDepthStencilAttachment(depthAtt) ? &depthAtt :
|
const auto* selectedDepthStencilAttachment = isUsableDepthStencilAttachment(depthAtt) ? &depthAtt :
|
||||||
(isUsableDepthStencilAttachment(stencilAtt) ? &stencilAtt : nullptr);
|
(isUsableDepthStencilAttachment(stencilAtt) ? &stencilAtt : nullptr);
|
||||||
|
// Depth-less default-FBO flavor: nothing in this pass touches depth/stencil
|
||||||
|
// and their content is undefined anyway (EGL swap), so drop the attachment
|
||||||
|
// and its whole tile load + store.
|
||||||
|
if (isDefaultFbo && !includeDefaultFboDepthStencil) {
|
||||||
|
selectedDepthStencilAttachment = nullptr;
|
||||||
|
}
|
||||||
const Bool hasDistinctDepthAndStencilAttachments =
|
const Bool hasDistinctDepthAndStencilAttachments =
|
||||||
isUsableDepthStencilAttachment(depthAtt) && isUsableDepthStencilAttachment(stencilAtt) &&
|
isUsableDepthStencilAttachment(depthAtt) && isUsableDepthStencilAttachment(stencilAtt) &&
|
||||||
!sameDepthStencilAttachmentObject(depthAtt, stencilAtt);
|
!sameDepthStencilAttachmentObject(depthAtt, stencilAtt);
|
||||||
@@ -994,6 +1053,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
VkImageLayout trackedDepthLayout = isDefaultFbo ?
|
VkImageLayout trackedDepthLayout = isDefaultFbo ?
|
||||||
m_swapchainObject.GetDepthStencilImageLayout(swapchainImageIndex) :
|
m_swapchainObject.GetDepthStencilImageLayout(swapchainImageIndex) :
|
||||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||||
|
// EGL 1.5 §3.10.1: every ancillary (depth/stencil) buffer's content is
|
||||||
|
// undefined after a swap, so the first default-FBO pass of a frame can
|
||||||
|
// skip the depth/stencil tile load outright.
|
||||||
|
if (isDefaultFbo && !m_swapchainObject.IsDepthStencilContentDefined(swapchainImageIndex)) {
|
||||||
|
trackedDepthLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
}
|
||||||
depthAttachmentDescription.flags = 0;
|
depthAttachmentDescription.flags = 0;
|
||||||
VkSampleCountFlagBits depthAttachmentSampleCount = VK_SAMPLE_COUNT_1_BIT;
|
VkSampleCountFlagBits depthAttachmentSampleCount = VK_SAMPLE_COUNT_1_BIT;
|
||||||
Int depthAttachmentId = 0;
|
Int depthAttachmentId = 0;
|
||||||
@@ -1122,6 +1187,22 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
}
|
}
|
||||||
const Bool hasDepthStencilAttachment = depthAttachmentRef.attachment != VK_ATTACHMENT_UNUSED;
|
const Bool hasDepthStencilAttachment = depthAttachmentRef.attachment != VK_ATTACHMENT_UNUSED;
|
||||||
|
|
||||||
|
// Declare only the used colour-reference span. The GL draw-buffer array
|
||||||
|
// always spans 8 slots, so passes used to declare colorAttachmentCount=8
|
||||||
|
// with trailing VK_ATTACHMENT_UNUSED holes - and Adreno configures its
|
||||||
|
// per-pixel render-backend/export path from the DECLARED count, so every
|
||||||
|
// fragment of every pass paid the 8-target export cost (measured on
|
||||||
|
// Adreno 650 / MC 26.2: 11.9 -> 7.5 ms of GPU time per frame, with the
|
||||||
|
// single-quad swapchain blit pass alone dropping 1.26 -> 0.40 ms).
|
||||||
|
// Interior GL_NONE holes keep their slots so fragment-output locations
|
||||||
|
// still line up; a fragment output at a location past the trimmed count
|
||||||
|
// is discarded, which is exactly GL's semantic for writing to a draw
|
||||||
|
// buffer set to GL_NONE.
|
||||||
|
while (!colorAttachmentRefs.empty() &&
|
||||||
|
colorAttachmentRefs.back().attachment == VK_ATTACHMENT_UNUSED) {
|
||||||
|
colorAttachmentRefs.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
// Subpass
|
// Subpass
|
||||||
VkSubpassDescription subpassDesc;
|
VkSubpassDescription subpassDesc;
|
||||||
subpassDesc.flags = 0;
|
subpassDesc.flags = 0;
|
||||||
@@ -1330,6 +1411,17 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
renderPassBeginInfo.pClearValues = clearValues.data();
|
renderPassBeginInfo.pClearValues = clearValues.data();
|
||||||
|
|
||||||
vkCmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
vkCmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||||
|
// Pre-pass stream bookkeeping: this pass's attachment images are now
|
||||||
|
// referenced by the open frame recording.
|
||||||
|
if (s_textureManager != nullptr) {
|
||||||
|
for (const auto& tracked : renderPassEntry.trackedAttachmentLayouts) {
|
||||||
|
if (tracked.target == TrackedAttachmentTarget::Texture) {
|
||||||
|
if (const auto texture = tracked.texture.lock()) {
|
||||||
|
s_textureManager->StampTextureRecordingUse(texture.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for (const auto& pending: renderPassEntry.pendingClearAttachments) {
|
for (const auto& pending: renderPassEntry.pendingClearAttachments) {
|
||||||
if (pending.hasInlinePayload) {
|
if (pending.hasInlinePayload) {
|
||||||
if (s_renderPassManager != nullptr) {
|
if (s_renderPassManager != nullptr) {
|
||||||
@@ -1382,11 +1474,15 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
case TrackedAttachmentTarget::SwapchainColor:
|
case TrackedAttachmentTarget::SwapchainColor:
|
||||||
MOBILEGL_ASSERT(s_swapchainObject != nullptr, "EndRenderPass: swapchain object is null");
|
MOBILEGL_ASSERT(s_swapchainObject != nullptr, "EndRenderPass: swapchain object is null");
|
||||||
s_swapchainObject->SetImageLayout(trackedAttachment.swapchainImageIndex, trackedAttachment.finalLayout);
|
s_swapchainObject->SetImageLayout(trackedAttachment.swapchainImageIndex, trackedAttachment.finalLayout);
|
||||||
|
// The pass stored into the attachment: its content is defined
|
||||||
|
// until the image is next presented.
|
||||||
|
s_swapchainObject->SetImageContentDefined(trackedAttachment.swapchainImageIndex, true);
|
||||||
break;
|
break;
|
||||||
case TrackedAttachmentTarget::SwapchainDepthStencil:
|
case TrackedAttachmentTarget::SwapchainDepthStencil:
|
||||||
MOBILEGL_ASSERT(s_swapchainObject != nullptr, "EndRenderPass: swapchain object is null");
|
MOBILEGL_ASSERT(s_swapchainObject != nullptr, "EndRenderPass: swapchain object is null");
|
||||||
s_swapchainObject->SetDepthStencilImageLayout(trackedAttachment.swapchainImageIndex,
|
s_swapchainObject->SetDepthStencilImageLayout(trackedAttachment.swapchainImageIndex,
|
||||||
trackedAttachment.finalLayout);
|
trackedAttachment.finalLayout);
|
||||||
|
s_swapchainObject->SetDepthStencilContentDefined(trackedAttachment.swapchainImageIndex, true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
MOBILEGL_ASSERT(false, "EndRenderPass: unsupported tracked attachment target=%d",
|
MOBILEGL_ASSERT(false, "EndRenderPass: unsupported tracked attachment target=%d",
|
||||||
|
|||||||
@@ -188,8 +188,22 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
HashType ComputeHash(
|
HashType ComputeHash(
|
||||||
const MG_State::GLState::FramebufferObject& fbo,
|
const MG_State::GLState::FramebufferObject& fbo,
|
||||||
Uint32 swapchainImageIndex,
|
Uint32 swapchainImageIndex,
|
||||||
Bool includePendingClear = true);
|
Bool includePendingClear = true,
|
||||||
RenderPassEntry& GetOrCreateRenderPass(const MG_State::GLState::FramebufferObject& fbo, Uint32 swapchainImageIndex);
|
Bool includeDefaultFboDepthStencil = true);
|
||||||
|
// drawUsesDepthStencil: whether the operation about to run inside the pass
|
||||||
|
// reads or writes the depth/stencil buffer (depth test or stencil test
|
||||||
|
// enabled, or a depth/stencil clear). Only consulted for the DEFAULT
|
||||||
|
// framebuffer: EGL undefines its ancillary buffers at every swap, so a
|
||||||
|
// default-FBO pass whose draws provably never touch depth/stencil is
|
||||||
|
// created WITHOUT the depth attachment - on a tiler that skips the whole
|
||||||
|
// depth tile load AND store. The flavor only escalates: once a pass with
|
||||||
|
// depth is active, later depth-less draws keep using it, and a depth-using
|
||||||
|
// draw against a depth-less active pass resolves to a new (incompatible)
|
||||||
|
// entry, which the caller's compatibility check turns into a pass split;
|
||||||
|
// the new pass's depth loads DONT_CARE (content was undefined all along).
|
||||||
|
RenderPassEntry& GetOrCreateRenderPass(const MG_State::GLState::FramebufferObject& fbo,
|
||||||
|
Uint32 swapchainImageIndex,
|
||||||
|
Bool drawUsesDepthStencil = true);
|
||||||
void QueueRenderbufferClear(GLbitfield mask, const ClearFramebufferPayload& clearPayload,
|
void QueueRenderbufferClear(GLbitfield mask, const ClearFramebufferPayload& clearPayload,
|
||||||
const MG_State::GLState::FramebufferObject& drawFbo);
|
const MG_State::GLState::FramebufferObject& drawFbo);
|
||||||
void QueueRenderbufferClear(const ClearAttachmentPayload& clearPayload,
|
void QueueRenderbufferClear(const ClearAttachmentPayload& clearPayload,
|
||||||
@@ -231,6 +245,10 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
Uint64 m_rpFastTexEpoch = 0;
|
Uint64 m_rpFastTexEpoch = 0;
|
||||||
Uint64 m_rpFastRbEpoch = 0;
|
Uint64 m_rpFastRbEpoch = 0;
|
||||||
Uint64 m_rpFastRenderPassHash = 0;
|
Uint64 m_rpFastRenderPassHash = 0;
|
||||||
|
// Whether the memoized entry carries a depth/stencil attachment; a
|
||||||
|
// default-FBO resolution whose effective depth request differs must
|
||||||
|
// miss the memo (the depth-less/depth-full flavors hash differently).
|
||||||
|
Bool m_rpFastHadDepthStencil = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct RenderbufferResource {
|
struct RenderbufferResource {
|
||||||
|
|||||||
@@ -1049,6 +1049,16 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VkTextureManager::StampTextureRecordingUse(MG_State::GLState::ITextureObject* texture) {
|
||||||
|
if (texture == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto it = m_textureResources.find(MakeTextureIdentity(texture));
|
||||||
|
if (it != m_textureResources.end()) {
|
||||||
|
it->second.lastRecordingGeneration = m_recordingGeneration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void VkTextureManager::UpdateTrackedImageLayout(MG_State::GLState::ITextureObject* texture, VkImageLayout newLayout) {
|
void VkTextureManager::UpdateTrackedImageLayout(MG_State::GLState::ITextureObject* texture, VkImageLayout newLayout) {
|
||||||
MOBILEGL_ASSERT(texture != nullptr, "UpdateTrackedImageLayout: texture is null");
|
MOBILEGL_ASSERT(texture != nullptr, "UpdateTrackedImageLayout: texture is null");
|
||||||
auto it = m_textureResources.find(MakeTextureIdentity(texture));
|
auto it = m_textureResources.find(MakeTextureIdentity(texture));
|
||||||
@@ -1076,6 +1086,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
MOBILEGL_ASSERT(writtenMipLevel < resource.mipLevels,
|
MOBILEGL_ASSERT(writtenMipLevel < resource.mipLevels,
|
||||||
"UpdateTrackedImageLayoutAfterAttachmentWrite: textureId=%d mipLevel=%u out of range %u",
|
"UpdateTrackedImageLayoutAfterAttachmentWrite: textureId=%d mipLevel=%u out of range %u",
|
||||||
texture->GetExternalIndex(), writtenMipLevel, resource.mipLevels);
|
texture->GetExternalIndex(), writtenMipLevel, resource.mipLevels);
|
||||||
|
// Pre-pass stream bookkeeping: the render pass that just ended wrote this image.
|
||||||
|
StampResourceRecordingUse(resource);
|
||||||
|
|
||||||
if (resource.layout != newLayout && resource.mipLevels > 1) {
|
if (resource.layout != newLayout && resource.mipLevels > 1) {
|
||||||
VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||||
@@ -1160,6 +1172,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
VK_ACCESS_SHADER_READ_BIT, resource->aspect, 0, resource->mipLevels,
|
VK_ACCESS_SHADER_READ_BIT, resource->aspect, 0, resource->mipLevels,
|
||||||
resource->arrayLayers);
|
resource->arrayLayers);
|
||||||
MOBILEGL_ASSERT(ok, "TransitionTextureForSampling: transition failed for textureId=%d", texture.GetExternalIndex());
|
MOBILEGL_ASSERT(ok, "TransitionTextureForSampling: transition failed for textureId=%d", texture.GetExternalIndex());
|
||||||
|
// Pre-pass stream bookkeeping: a command referencing the image was recorded.
|
||||||
|
StampResourceRecordingUse(*resource);
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1189,6 +1203,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
resource->aspect, 0, resource->mipLevels, resource->arrayLayers);
|
resource->aspect, 0, resource->mipLevels, resource->arrayLayers);
|
||||||
MOBILEGL_ASSERT(ok, "TransitionTextureForStorageImage: transition failed for textureId=%d",
|
MOBILEGL_ASSERT(ok, "TransitionTextureForStorageImage: transition failed for textureId=%d",
|
||||||
texture.GetExternalIndex());
|
texture.GetExternalIndex());
|
||||||
|
// Pre-pass stream bookkeeping: a command referencing the image was recorded.
|
||||||
|
StampResourceRecordingUse(*resource);
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1420,8 +1436,17 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const Bool isMultisampleTexture = IsMultisampleTextureUploadTarget(uploadTarget);
|
const Bool isMultisampleTexture = IsMultisampleTextureUploadTarget(uploadTarget);
|
||||||
|
// A texture that has only ever defined level 0 gets a single-level backing
|
||||||
|
// (ANGLE's model). Preallocating the full chain put every render target
|
||||||
|
// onto Adreno's multi-mip image layout and grew each texture by a third
|
||||||
|
// for levels most textures never define. Once a second level is defined
|
||||||
|
// the backing is recreated ONE time with the full chain (the
|
||||||
|
// preserve-copy path below carries the pixels over), so sequentially-
|
||||||
|
// defined atlas mips do not recreate per level, and glGenerateMipmap -
|
||||||
|
// which defines every level before syncing - works unchanged.
|
||||||
const Uint32 backingMipLevels =
|
const Uint32 backingMipLevels =
|
||||||
isMultisampleTexture ? 1u : std::max(mipLevels, ComputeFullMipLevelCount(texelSize));
|
isMultisampleTexture ? 1u
|
||||||
|
: (mipLevels > 1 ? std::max(mipLevels, ComputeFullMipLevelCount(texelSize)) : 1u);
|
||||||
TextureShapeInfo shapeInfo{};
|
TextureShapeInfo shapeInfo{};
|
||||||
const Bool supportedShape = TryResolveTextureShapeInfo(texture, uploadTarget, texelSize, shapeInfo);
|
const Bool supportedShape = TryResolveTextureShapeInfo(texture, uploadTarget, texelSize, shapeInfo);
|
||||||
MOBILEGL_ASSERT(supportedShape,
|
MOBILEGL_ASSERT(supportedShape,
|
||||||
|
|||||||
@@ -172,6 +172,13 @@ public:
|
|||||||
// NeedsStorageImagePreparation cannot ask for a recreate that will never happen.
|
// NeedsStorageImagePreparation cannot ask for a recreate that will never happen.
|
||||||
Bool storageUsageResolved = false;
|
Bool storageUsageResolved = false;
|
||||||
Uint16 syncedTextureParamsVersion = 0;
|
Uint16 syncedTextureParamsVersion = 0;
|
||||||
|
// Recording generation (VkTextureManager::GetRecordingGeneration) of the last
|
||||||
|
// command referencing this image that was recorded into the CURRENT frame
|
||||||
|
// command buffer. An image untouched by the open recording may have its
|
||||||
|
// out-of-pass work (deferred clears, sampled-layout transitions) recorded
|
||||||
|
// into the frame's PRE command buffer - which executes strictly before the
|
||||||
|
// frame's commands - instead of splitting the active render pass.
|
||||||
|
Uint64 lastRecordingGeneration = 0;
|
||||||
// Snapshot of ITextureObject::GetContentVersion() at the last successful sync;
|
// Snapshot of ITextureObject::GetContentVersion() at the last successful sync;
|
||||||
// lets SyncTexture skip the whole re-check/re-upload when content is unchanged.
|
// lets SyncTexture skip the whole re-check/re-upload when content is unchanged.
|
||||||
Uint64 syncedContentVersion = 0;
|
Uint64 syncedContentVersion = 0;
|
||||||
@@ -207,6 +214,7 @@ public:
|
|||||||
std::swap(this->usageFlags, that.usageFlags);
|
std::swap(this->usageFlags, that.usageFlags);
|
||||||
std::swap(this->storageUsageResolved, that.storageUsageResolved);
|
std::swap(this->storageUsageResolved, that.storageUsageResolved);
|
||||||
std::swap(this->syncedTextureParamsVersion, that.syncedTextureParamsVersion);
|
std::swap(this->syncedTextureParamsVersion, that.syncedTextureParamsVersion);
|
||||||
|
std::swap(this->lastRecordingGeneration, that.lastRecordingGeneration);
|
||||||
std::swap(this->syncedContentVersion, that.syncedContentVersion);
|
std::swap(this->syncedContentVersion, that.syncedContentVersion);
|
||||||
std::swap(this->syncedMipLevelCount, that.syncedMipLevelCount);
|
std::swap(this->syncedMipLevelCount, that.syncedMipLevelCount);
|
||||||
}
|
}
|
||||||
@@ -307,6 +315,21 @@ public:
|
|||||||
VkImageLayout newLayout);
|
VkImageLayout newLayout);
|
||||||
Bool TransitionTextureForSampling(VkCommandBuffer commandBuffer, MG_State::GLState::ITextureObject& texture);
|
Bool TransitionTextureForSampling(VkCommandBuffer commandBuffer, MG_State::GLState::ITextureObject& texture);
|
||||||
Bool TransitionTextureForStorageImage(VkCommandBuffer commandBuffer, MG_State::GLState::ITextureObject& texture);
|
Bool TransitionTextureForStorageImage(VkCommandBuffer commandBuffer, MG_State::GLState::ITextureObject& texture);
|
||||||
|
|
||||||
|
// Recording-generation bookkeeping for the pre-pass command stream. The
|
||||||
|
// generation advances every time the frame command buffer (re)begins
|
||||||
|
// recording; a resource whose stamp does not match was not referenced by
|
||||||
|
// any command in the open recording, so its out-of-pass work may safely
|
||||||
|
// execute ahead of the whole recording (in the pre command buffer).
|
||||||
|
void AdvanceRecordingGeneration() { ++m_recordingGeneration; }
|
||||||
|
void StampResourceRecordingUse(TextureResource& resource) const {
|
||||||
|
resource.lastRecordingGeneration = m_recordingGeneration;
|
||||||
|
}
|
||||||
|
// Map-lookup variant for callers that only hold the GL texture object.
|
||||||
|
void StampTextureRecordingUse(MG_State::GLState::ITextureObject* texture);
|
||||||
|
Bool WasTouchedThisRecording(const TextureResource& resource) const {
|
||||||
|
return resource.lastRecordingGeneration == m_recordingGeneration;
|
||||||
|
}
|
||||||
// Records that this texture is bound to a GL image unit, so its image must carry
|
// Records that this texture is bound to a GL image unit, so its image must carry
|
||||||
// VK_IMAGE_USAGE_STORAGE_BIT. Must be called before NeedsStorageImagePreparation, and
|
// VK_IMAGE_USAGE_STORAGE_BIT. Must be called before NeedsStorageImagePreparation, and
|
||||||
// therefore before the render pass is committed: an image that has to be upgraded is
|
// therefore before the render pass is committed: an image that has to be upgraded is
|
||||||
@@ -364,6 +387,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
// Bumped in SyncTextureResource right after vmaCreateImage(texture). See GetTextureImageEpoch().
|
// Bumped in SyncTextureResource right after vmaCreateImage(texture). See GetTextureImageEpoch().
|
||||||
Uint64 m_textureImageEpoch = 1;
|
Uint64 m_textureImageEpoch = 1;
|
||||||
|
// See AdvanceRecordingGeneration. Starts above every resource's default
|
||||||
|
// stamp of 0 so a fresh resource counts as untouched.
|
||||||
|
Uint64 m_recordingGeneration = 1;
|
||||||
|
|
||||||
Bool SyncTexture(MG_State::GLState::ITextureObject &texture,
|
Bool SyncTexture(MG_State::GLState::ITextureObject &texture,
|
||||||
TextureResource &outResource);
|
TextureResource &outResource);
|
||||||
|
|||||||
@@ -217,6 +217,53 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
return static_cast<Int>((static_cast<Int64>(value) * toExtent + fromExtent / 2) / fromExtent);
|
return static_cast<Int>((static_cast<Int64>(value) * toExtent + fromExtent / 2) / fromExtent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Redundant dynamic-state elimination for the per-draw hot path: within one
|
||||||
|
// command-buffer recording, a vkCmdSet* whose values already match what the
|
||||||
|
// command buffer holds is skipped. Valid because every PipelineFactory
|
||||||
|
// pipeline declares the same eight dynamic states, so the values persist
|
||||||
|
// across those pipeline binds; the shadow resets whenever a recording
|
||||||
|
// (re)begins, and whenever an auxiliary pipeline with a narrower dynamic
|
||||||
|
// set (blit, depth-mipmap) binds - their static state makes the
|
||||||
|
// corresponding dynamic values undefined per the spec.
|
||||||
|
struct DynamicStateShadow {
|
||||||
|
Bool viewportValid = false;
|
||||||
|
VkViewport viewport{};
|
||||||
|
Bool scissorValid = false;
|
||||||
|
VkRect2D scissor{};
|
||||||
|
Bool blendConstantsValid = false;
|
||||||
|
Float blendConstants[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||||
|
Bool depthBiasValid = false;
|
||||||
|
Float depthBiasConstantFactor = 0.0f;
|
||||||
|
Float depthBiasSlopeFactor = 0.0f;
|
||||||
|
Bool lineWidthValid = false;
|
||||||
|
Float lineWidth = 0.0f;
|
||||||
|
Bool stencilValid = false;
|
||||||
|
Uint32 stencilFrontCompareMask = 0;
|
||||||
|
Uint32 stencilBackCompareMask = 0;
|
||||||
|
Uint32 stencilFrontWriteMask = 0;
|
||||||
|
Uint32 stencilBackWriteMask = 0;
|
||||||
|
Uint32 stencilFrontReference = 0;
|
||||||
|
Uint32 stencilBackReference = 0;
|
||||||
|
};
|
||||||
|
static DynamicStateShadow g_dynamicStateShadow;
|
||||||
|
|
||||||
|
static void ResetDynamicStateShadow() {
|
||||||
|
g_dynamicStateShadow = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ShadowedSetScissor(VkCommandBuffer commandBuffer, const VkRect2D& scissor) {
|
||||||
|
auto& shadow = g_dynamicStateShadow;
|
||||||
|
if (shadow.scissorValid && shadow.scissor.offset.x == scissor.offset.x &&
|
||||||
|
shadow.scissor.offset.y == scissor.offset.y &&
|
||||||
|
shadow.scissor.extent.width == scissor.extent.width &&
|
||||||
|
shadow.scissor.extent.height == scissor.extent.height) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
shadow.scissorValid = true;
|
||||||
|
shadow.scissor = scissor;
|
||||||
|
vkCmdSetScissor(commandBuffer, 0, 1, &scissor);
|
||||||
|
}
|
||||||
|
|
||||||
static void ApplyGLViewportState(VkCommandBuffer commandBuffer,
|
static void ApplyGLViewportState(VkCommandBuffer commandBuffer,
|
||||||
const IntVec2& framebufferExtent,
|
const IntVec2& framebufferExtent,
|
||||||
VkSurfaceTransformFlagBitsKHR preTransform,
|
VkSurfaceTransformFlagBitsKHR preTransform,
|
||||||
@@ -246,6 +293,14 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
viewport.height = static_cast<float>(viewportHeight);
|
viewport.height = static_cast<float>(viewportHeight);
|
||||||
viewport.minDepth = depthRange.x();
|
viewport.minDepth = depthRange.x();
|
||||||
viewport.maxDepth = depthRange.y();
|
viewport.maxDepth = depthRange.y();
|
||||||
|
auto& shadow = g_dynamicStateShadow;
|
||||||
|
if (shadow.viewportValid && shadow.viewport.x == viewport.x && shadow.viewport.y == viewport.y &&
|
||||||
|
shadow.viewport.width == viewport.width && shadow.viewport.height == viewport.height &&
|
||||||
|
shadow.viewport.minDepth == viewport.minDepth && shadow.viewport.maxDepth == viewport.maxDepth) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
shadow.viewportValid = true;
|
||||||
|
shadow.viewport = viewport;
|
||||||
vkCmdSetViewport(commandBuffer, 0, 1, &viewport);
|
vkCmdSetViewport(commandBuffer, 0, 1, &viewport);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,6 +312,17 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
blendColor.z(),
|
blendColor.z(),
|
||||||
blendColor.w(),
|
blendColor.w(),
|
||||||
};
|
};
|
||||||
|
auto& shadow = g_dynamicStateShadow;
|
||||||
|
if (shadow.blendConstantsValid && shadow.blendConstants[0] == blendConstants[0] &&
|
||||||
|
shadow.blendConstants[1] == blendConstants[1] && shadow.blendConstants[2] == blendConstants[2] &&
|
||||||
|
shadow.blendConstants[3] == blendConstants[3]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
shadow.blendConstantsValid = true;
|
||||||
|
shadow.blendConstants[0] = blendConstants[0];
|
||||||
|
shadow.blendConstants[1] = blendConstants[1];
|
||||||
|
shadow.blendConstants[2] = blendConstants[2];
|
||||||
|
shadow.blendConstants[3] = blendConstants[3];
|
||||||
vkCmdSetBlendConstants(commandBuffer, blendConstants);
|
vkCmdSetBlendConstants(commandBuffer, blendConstants);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,8 +338,17 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void ApplyPolygonOffsetState(VkCommandBuffer commandBuffer) {
|
static void ApplyPolygonOffsetState(VkCommandBuffer commandBuffer) {
|
||||||
vkCmdSetDepthBias(commandBuffer, MG_State::pGLContext->GetPolygonOffsetUnits(), 0.0f,
|
const Float constantFactor = MG_State::pGLContext->GetPolygonOffsetUnits();
|
||||||
MG_State::pGLContext->GetPolygonOffsetFactor());
|
const Float slopeFactor = MG_State::pGLContext->GetPolygonOffsetFactor();
|
||||||
|
auto& shadow = g_dynamicStateShadow;
|
||||||
|
if (shadow.depthBiasValid && shadow.depthBiasConstantFactor == constantFactor &&
|
||||||
|
shadow.depthBiasSlopeFactor == slopeFactor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
shadow.depthBiasValid = true;
|
||||||
|
shadow.depthBiasConstantFactor = constantFactor;
|
||||||
|
shadow.depthBiasSlopeFactor = slopeFactor;
|
||||||
|
vkCmdSetDepthBias(commandBuffer, constantFactor, 0.0f, slopeFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ApplyLineWidthState(VkCommandBuffer commandBuffer) {
|
static void ApplyLineWidthState(VkCommandBuffer commandBuffer) {
|
||||||
@@ -288,6 +363,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
lineWidth = maxLineWidth;
|
lineWidth = maxLineWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
auto& shadow = g_dynamicStateShadow;
|
||||||
|
if (shadow.lineWidthValid && shadow.lineWidth == lineWidth) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
shadow.lineWidthValid = true;
|
||||||
|
shadow.lineWidth = lineWidth;
|
||||||
vkCmdSetLineWidth(commandBuffer, lineWidth);
|
vkCmdSetLineWidth(commandBuffer, lineWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,15 +417,31 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
static void ApplyStencilState(VkCommandBuffer commandBuffer) {
|
static void ApplyStencilState(VkCommandBuffer commandBuffer) {
|
||||||
const StencilFaceState& frontStencil = MG_State::pGLContext->GetStencilState(StencilFace::Front);
|
const StencilFaceState& frontStencil = MG_State::pGLContext->GetStencilState(StencilFace::Front);
|
||||||
const StencilFaceState& backStencil = MG_State::pGLContext->GetStencilState(StencilFace::Back);
|
const StencilFaceState& backStencil = MG_State::pGLContext->GetStencilState(StencilFace::Back);
|
||||||
|
const Uint32 frontReference = static_cast<Uint32>(std::max(frontStencil.Ref, 0));
|
||||||
|
const Uint32 backReference = static_cast<Uint32>(std::max(backStencil.Ref, 0));
|
||||||
|
|
||||||
|
auto& shadow = g_dynamicStateShadow;
|
||||||
|
if (shadow.stencilValid && shadow.stencilFrontCompareMask == frontStencil.ValueMask &&
|
||||||
|
shadow.stencilBackCompareMask == backStencil.ValueMask &&
|
||||||
|
shadow.stencilFrontWriteMask == frontStencil.WriteMask &&
|
||||||
|
shadow.stencilBackWriteMask == backStencil.WriteMask &&
|
||||||
|
shadow.stencilFrontReference == frontReference && shadow.stencilBackReference == backReference) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
shadow.stencilValid = true;
|
||||||
|
shadow.stencilFrontCompareMask = frontStencil.ValueMask;
|
||||||
|
shadow.stencilBackCompareMask = backStencil.ValueMask;
|
||||||
|
shadow.stencilFrontWriteMask = frontStencil.WriteMask;
|
||||||
|
shadow.stencilBackWriteMask = backStencil.WriteMask;
|
||||||
|
shadow.stencilFrontReference = frontReference;
|
||||||
|
shadow.stencilBackReference = backReference;
|
||||||
|
|
||||||
vkCmdSetStencilCompareMask(commandBuffer, VK_STENCIL_FACE_FRONT_BIT, frontStencil.ValueMask);
|
vkCmdSetStencilCompareMask(commandBuffer, VK_STENCIL_FACE_FRONT_BIT, frontStencil.ValueMask);
|
||||||
vkCmdSetStencilCompareMask(commandBuffer, VK_STENCIL_FACE_BACK_BIT, backStencil.ValueMask);
|
vkCmdSetStencilCompareMask(commandBuffer, VK_STENCIL_FACE_BACK_BIT, backStencil.ValueMask);
|
||||||
vkCmdSetStencilWriteMask(commandBuffer, VK_STENCIL_FACE_FRONT_BIT, frontStencil.WriteMask);
|
vkCmdSetStencilWriteMask(commandBuffer, VK_STENCIL_FACE_FRONT_BIT, frontStencil.WriteMask);
|
||||||
vkCmdSetStencilWriteMask(commandBuffer, VK_STENCIL_FACE_BACK_BIT, backStencil.WriteMask);
|
vkCmdSetStencilWriteMask(commandBuffer, VK_STENCIL_FACE_BACK_BIT, backStencil.WriteMask);
|
||||||
vkCmdSetStencilReference(commandBuffer, VK_STENCIL_FACE_FRONT_BIT,
|
vkCmdSetStencilReference(commandBuffer, VK_STENCIL_FACE_FRONT_BIT, frontReference);
|
||||||
static_cast<Uint32>(std::max(frontStencil.Ref, 0)));
|
vkCmdSetStencilReference(commandBuffer, VK_STENCIL_FACE_BACK_BIT, backReference);
|
||||||
vkCmdSetStencilReference(commandBuffer, VK_STENCIL_FACE_BACK_BIT,
|
|
||||||
static_cast<Uint32>(std::max(backStencil.Ref, 0)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class NumericDomain {
|
enum class NumericDomain {
|
||||||
@@ -3653,6 +3750,10 @@ void main() {
|
|||||||
vkCmdSetScissor(frame.commandBuffer, 0, 1, &scissor);
|
vkCmdSetScissor(frame.commandBuffer, 0, 1, &scissor);
|
||||||
|
|
||||||
vkCmdBindPipeline(frame.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
vkCmdBindPipeline(frame.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||||
|
// The depth-mipmap pipeline's narrower dynamic set (viewport/scissor
|
||||||
|
// only) leaves the other dynamic states undefined; its raw scissor
|
||||||
|
// and viewport writes also bypass the shadow.
|
||||||
|
ResetDynamicStateShadow();
|
||||||
|
|
||||||
std::fill(depthProgramData,
|
std::fill(depthProgramData,
|
||||||
depthProgramData + m_depthMipmapResources.program->GetUBOSize(),
|
depthProgramData + m_depthMipmapResources.program->GetUBOSize(),
|
||||||
@@ -3940,12 +4041,15 @@ void main() {
|
|||||||
payload.backStencilCompareOp = VK_COMPARE_OP_ALWAYS;
|
payload.backStencilCompareOp = VK_COMPARE_OP_ALWAYS;
|
||||||
}
|
}
|
||||||
const Uint32 fragmentOutputMask = programObj.activeFragmentOutputLocationMask;
|
const Uint32 fragmentOutputMask = programObj.activeFragmentOutputLocationMask;
|
||||||
MOBILEGL_ASSERT(
|
// Outputs at locations past the render pass's trimmed colour span are
|
||||||
(fragmentOutputMask >> payload.colorAttachmentCount) == 0,
|
// simply discarded - GL's semantic for a fragment output whose draw
|
||||||
"GetOrCreatePipeline: fragmentOutputMask=0x%x exceeds colorAttachmentCount=%u for program=%u",
|
// buffer is GL_NONE (the trailing UNUSED slots no longer occupy
|
||||||
fragmentOutputMask,
|
// references, see GetOrCreateRenderPass).
|
||||||
payload.colorAttachmentCount,
|
if ((fragmentOutputMask >> payload.colorAttachmentCount) != 0) {
|
||||||
program.GetExternalIndex());
|
MGLOG_D("GetOrCreatePipeline: fragmentOutputMask=0x%x exceeds colorAttachmentCount=%u for program=%u; "
|
||||||
|
"outputs past the span are discarded",
|
||||||
|
fragmentOutputMask, payload.colorAttachmentCount, program.GetExternalIndex());
|
||||||
|
}
|
||||||
MOBILEGL_ASSERT(payload.colorAttachmentCount <= PipelineFactory::PipelineCreatePayload::kMaxColorAttachments,
|
MOBILEGL_ASSERT(payload.colorAttachmentCount <= PipelineFactory::PipelineCreatePayload::kMaxColorAttachments,
|
||||||
"GetOrCreatePipeline: colorAttachmentCount=%u exceeds payload capacity",
|
"GetOrCreatePipeline: colorAttachmentCount=%u exceeds payload capacity",
|
||||||
payload.colorAttachmentCount);
|
payload.colorAttachmentCount);
|
||||||
@@ -4397,8 +4501,30 @@ void main() {
|
|||||||
static_cast<Int>(textureResource->layout));
|
static_cast<Int>(textureResource->layout));
|
||||||
if (m_clearManager->HasPendingClear(sampledTexture) ||
|
if (m_clearManager->HasPendingClear(sampledTexture) ||
|
||||||
!IsValidSampledImageLayout(textureResource->layout)) {
|
!IsValidSampledImageLayout(textureResource->layout)) {
|
||||||
|
// Out-of-pass work is needed (deferred clear materialization or
|
||||||
|
// a sampled-layout transition). When the open frame recording
|
||||||
|
// has not referenced this image yet, that work can execute
|
||||||
|
// ahead of the WHOLE recording - record it into the pre-pass
|
||||||
|
// stream instead of splitting the active render pass (ANGLE's
|
||||||
|
// outside-render-pass command stream, restricted to the
|
||||||
|
// provably reorderable case).
|
||||||
|
if (activeRenderPass != nullptr &&
|
||||||
|
!m_frameContext.GetCurrent().hasPreCommandBufferRecorded &&
|
||||||
|
!m_textureManager->WasTouchedThisRecording(*textureResource)) {
|
||||||
|
VkCommandBuffer preCommandBuffer = m_frameContext.BeginPreCommandRecording();
|
||||||
|
const Bool preClearReady =
|
||||||
|
MaterializePendingClearForTexture(preCommandBuffer, *sampledTexture);
|
||||||
|
MOBILEGL_ASSERT(preClearReady,
|
||||||
|
"%s: pre-pass MaterializePendingClearForTexture failed for textureId=%d",
|
||||||
|
__func__, sampledTexture->GetExternalIndex());
|
||||||
|
const Bool preTransitionReady =
|
||||||
|
m_textureManager->TransitionTextureForSampling(preCommandBuffer, *sampledTexture);
|
||||||
|
MOBILEGL_ASSERT(preTransitionReady,
|
||||||
|
"%s: pre-pass TransitionTextureForSampling failed for textureId=%d",
|
||||||
|
__func__, sampledTexture->GetExternalIndex());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
needSampledTextureTransitions = true;
|
needSampledTextureTransitions = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4422,16 +4548,28 @@ void main() {
|
|||||||
MOBILEGL_ASSERT(transitionedResource != nullptr,
|
MOBILEGL_ASSERT(transitionedResource != nullptr,
|
||||||
"%s: post-transition SyncTextureAndGetDescriptor failed for textureId=%d",
|
"%s: post-transition SyncTextureAndGetDescriptor failed for textureId=%d",
|
||||||
__func__, sampledTexture->GetExternalIndex());
|
__func__, sampledTexture->GetExternalIndex());
|
||||||
|
// Pre-pass stream bookkeeping: the draw about to be recorded reads
|
||||||
|
// this image, so later out-of-pass work on it can no longer jump
|
||||||
|
// ahead of the recording.
|
||||||
|
m_textureManager->StampResourceRecordingUse(*transitionedResource);
|
||||||
MGLOG_D("SetupDraw: sampled textureId=%d layout(after)=%s(%d)",
|
MGLOG_D("SetupDraw: sampled textureId=%d layout(after)=%s(%d)",
|
||||||
sampledTexture->GetExternalIndex(), VkImageLayoutToString(transitionedResource->layout),
|
sampledTexture->GetExternalIndex(), VkImageLayoutToString(transitionedResource->layout),
|
||||||
static_cast<Int>(transitionedResource->layout));
|
static_cast<Int>(transitionedResource->layout));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* renderPassEntry = &m_renderPassManager->GetOrCreateRenderPass(*drawFbo, m_imageIndexAcquired);
|
// Depth/stencil participation of THIS draw, for the default-FBO depth-less
|
||||||
|
// pass flavor (GL: a disabled depth/stencil test neither reads nor writes
|
||||||
|
// its buffer).
|
||||||
|
const Bool drawUsesDepthStencil =
|
||||||
|
MG_State::pGLContext->IsCapabilityEnabled(CapabilityInput::DepthTest) ||
|
||||||
|
MG_State::pGLContext->IsCapabilityEnabled(CapabilityInput::StencilTest);
|
||||||
|
auto* renderPassEntry =
|
||||||
|
&m_renderPassManager->GetOrCreateRenderPass(*drawFbo, m_imageIndexAcquired, drawUsesDepthStencil);
|
||||||
if (activeRenderPass && !activeRenderPass->CompatibleWith(*renderPassEntry)) {
|
if (activeRenderPass && !activeRenderPass->CompatibleWith(*renderPassEntry)) {
|
||||||
VkRenderPassManager::EndRenderPass(frame.commandBuffer);
|
VkRenderPassManager::EndRenderPass(frame.commandBuffer);
|
||||||
activeRenderPass = nullptr;
|
activeRenderPass = nullptr;
|
||||||
renderPassEntry = &m_renderPassManager->GetOrCreateRenderPass(*drawFbo, m_imageIndexAcquired);
|
renderPassEntry =
|
||||||
|
&m_renderPassManager->GetOrCreateRenderPass(*drawFbo, m_imageIndexAcquired, drawUsesDepthStencil);
|
||||||
}
|
}
|
||||||
if (renderPassEntry->attachmentCount == 0 || renderPassEntry->extent.x() <= 0 || renderPassEntry->extent.y() <= 0) {
|
if (renderPassEntry->attachmentCount == 0 || renderPassEntry->extent.x() <= 0 || renderPassEntry->extent.y() <= 0) {
|
||||||
MGLOG_D("SetupDraw skipped: drawFbo=%u resolved to an empty render pass (attachmentCount=%u extent=%dx%d)",
|
MGLOG_D("SetupDraw skipped: drawFbo=%u resolved to an empty render pass (attachmentCount=%u extent=%dx%d)",
|
||||||
@@ -4531,7 +4669,7 @@ void main() {
|
|||||||
scissor.offset = {0, 0};
|
scissor.offset = {0, 0};
|
||||||
scissor.extent = { (Uint)renderPassEntry->extent.x(), (Uint)renderPassEntry->extent.y() };
|
scissor.extent = { (Uint)renderPassEntry->extent.x(), (Uint)renderPassEntry->extent.y() };
|
||||||
}
|
}
|
||||||
vkCmdSetScissor(frame.commandBuffer, 0, 1, &scissor);
|
ShadowedSetScissor(frame.commandBuffer, scissor);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5222,8 +5360,12 @@ void main() {
|
|||||||
if (!m_clearManager->GetPendingClears(&texture, pendingClears)) {
|
if (!m_clearManager->GetPendingClears(&texture, pendingClears)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
MOBILEGL_ASSERT(VkRenderPassManager::GetActiveRenderPass() == nullptr,
|
// A pass may stay open on the FRAME command buffer while this clear is
|
||||||
"MaterializePendingClearForTexture requires no active render pass");
|
// recorded into the pre-pass stream (a different command buffer that
|
||||||
|
// executes strictly before the frame's commands).
|
||||||
|
MOBILEGL_ASSERT(VkRenderPassManager::GetActiveRenderPass() == nullptr ||
|
||||||
|
commandBuffer != m_frameContext.GetCurrent().commandBuffer,
|
||||||
|
"MaterializePendingClearForTexture requires no active render pass on the target buffer");
|
||||||
|
|
||||||
auto* resource = m_textureManager->SyncTextureAndGetDescriptor(texture);
|
auto* resource = m_textureManager->SyncTextureAndGetDescriptor(texture);
|
||||||
MOBILEGL_ASSERT(resource != nullptr,
|
MOBILEGL_ASSERT(resource != nullptr,
|
||||||
@@ -5453,7 +5595,10 @@ void main() {
|
|||||||
"TryBlitToDefaultFramebufferWithShader: failed to create sampled view for textureId=%d mip=%u",
|
"TryBlitToDefaultFramebufferWithShader: failed to create sampled view for textureId=%d mip=%u",
|
||||||
sourceTexture->GetExternalIndex(), srcBinding.mipLevel);
|
sourceTexture->GetExternalIndex(), srcBinding.mipLevel);
|
||||||
|
|
||||||
auto& renderPassEntry = m_renderPassManager->GetOrCreateRenderPass(drawFbo, m_imageIndexAcquired);
|
// A color-only blit never touches depth/stencil: let the default-FBO pass
|
||||||
|
// it opens skip the depth attachment (depth-less flavor).
|
||||||
|
auto& renderPassEntry =
|
||||||
|
m_renderPassManager->GetOrCreateRenderPass(drawFbo, m_imageIndexAcquired, /*drawUsesDepthStencil=*/false);
|
||||||
const Bool ok = VkRenderPassManager::BeginRenderPass(frame.commandBuffer, renderPassEntry);
|
const Bool ok = VkRenderPassManager::BeginRenderPass(frame.commandBuffer, renderPassEntry);
|
||||||
MOBILEGL_ASSERT(ok, "%s: BeginRenderPass failed", __func__);
|
MOBILEGL_ASSERT(ok, "%s: BeginRenderPass failed", __func__);
|
||||||
|
|
||||||
@@ -5469,6 +5614,10 @@ void main() {
|
|||||||
const VkPipeline pipeline = GetOrCreateBlitPipeline(renderPassEntry);
|
const VkPipeline pipeline = GetOrCreateBlitPipeline(renderPassEntry);
|
||||||
MOBILEGL_ASSERT(pipeline != VK_NULL_HANDLE, "TryBlitToDefaultFramebufferWithShader: blit pipeline is null");
|
MOBILEGL_ASSERT(pipeline != VK_NULL_HANDLE, "TryBlitToDefaultFramebufferWithShader: blit pipeline is null");
|
||||||
vkCmdBindPipeline(frame.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
vkCmdBindPipeline(frame.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||||
|
// The blit pipeline's narrower dynamic set (viewport/scissor only)
|
||||||
|
// leaves the other dynamic states undefined; its raw viewport/scissor
|
||||||
|
// writes also bypass the shadow.
|
||||||
|
ResetDynamicStateShadow();
|
||||||
|
|
||||||
auto* blitProgramData = static_cast<Uint8*>(m_blitResources.program->MapUBO());
|
auto* blitProgramData = static_cast<Uint8*>(m_blitResources.program->MapUBO());
|
||||||
MOBILEGL_ASSERT(blitProgramData != nullptr, "TryBlitToDefaultFramebufferWithShader: blit UBO is null");
|
MOBILEGL_ASSERT(blitProgramData != nullptr, "TryBlitToDefaultFramebufferWithShader: blit UBO is null");
|
||||||
@@ -6265,7 +6414,11 @@ void main() {
|
|||||||
frame.hasCommandBufferRecorded = true;
|
frame.hasCommandBufferRecorded = true;
|
||||||
m_lastPipelineValid = false; // command-buffer boundary: drop the pipeline memo
|
m_lastPipelineValid = false; // command-buffer boundary: drop the pipeline memo
|
||||||
}
|
}
|
||||||
if (!frame.hasCommandBufferRecorded) {
|
// The pre-pass stream must never be submitted later than the recording
|
||||||
|
// it was paired with (frame commands recorded after a pre-pass move
|
||||||
|
// rely on the moved work having executed first).
|
||||||
|
m_frameContext.EndPreCommandRecordingIfOpen();
|
||||||
|
if (!frame.hasCommandBufferRecorded && !frame.hasPreCommandBufferRecorded) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7400,8 +7553,18 @@ void main() {
|
|||||||
submitInfo.pWaitSemaphores = &waitSemaphore;
|
submitInfo.pWaitSemaphores = &waitSemaphore;
|
||||||
submitInfo.pWaitDstStageMask = &waitDstStageMask;
|
submitInfo.pWaitDstStageMask = &waitDstStageMask;
|
||||||
}
|
}
|
||||||
submitInfo.commandBufferCount = 1;
|
// The pre-pass stream, when recorded, executes strictly before the
|
||||||
submitInfo.pCommandBuffers = &frame.commandBuffer;
|
// frame's commands within the same submission.
|
||||||
|
VkCommandBuffer commandBuffers[2] = {VK_NULL_HANDLE, VK_NULL_HANDLE};
|
||||||
|
Uint32 commandBufferCount = 0;
|
||||||
|
if (frame.hasPreCommandBufferRecorded) {
|
||||||
|
commandBuffers[commandBufferCount++] = frame.preCommandBuffer;
|
||||||
|
}
|
||||||
|
if (frame.hasCommandBufferRecorded) {
|
||||||
|
commandBuffers[commandBufferCount++] = frame.commandBuffer;
|
||||||
|
}
|
||||||
|
submitInfo.commandBufferCount = commandBufferCount;
|
||||||
|
submitInfo.pCommandBuffers = commandBuffers;
|
||||||
const VkResult result = vkQueueSubmit(m_graphicsQueue, 1, &submitInfo, fence);
|
const VkResult result = vkQueueSubmit(m_graphicsQueue, 1, &submitInfo, fence);
|
||||||
if (result != VK_SUCCESS) {
|
if (result != VK_SUCCESS) {
|
||||||
MGLOG_E("SubmitPendingCommandBuffer: vkQueueSubmit returned %d", result);
|
MGLOG_E("SubmitPendingCommandBuffer: vkQueueSubmit returned %d", result);
|
||||||
@@ -7409,6 +7572,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
frame.imageAvailableSemaphoreConsumed = true;
|
frame.imageAvailableSemaphoreConsumed = true;
|
||||||
frame.hasCommandBufferRecorded = false;
|
frame.hasCommandBufferRecorded = false;
|
||||||
|
frame.hasPreCommandBufferRecorded = false;
|
||||||
RegisterSubmit(fence, pooledFence);
|
RegisterSubmit(fence, pooledFence);
|
||||||
frame.lastSubmitIndex = m_submitCounter;
|
frame.lastSubmitIndex = m_submitCounter;
|
||||||
return true;
|
return true;
|
||||||
@@ -7439,6 +7603,8 @@ void main() {
|
|||||||
}
|
}
|
||||||
m_frameContext.EndCommandRecording();
|
m_frameContext.EndCommandRecording();
|
||||||
}
|
}
|
||||||
|
m_frameContext.EndPreCommandRecordingIfOpen();
|
||||||
|
const Bool submittingPreCommandBuffer = frame.hasPreCommandBufferRecorded;
|
||||||
if (!SubmitPendingCommandBuffer(frame, fence, /*pooledFence=*/true)) {
|
if (!SubmitPendingCommandBuffer(frame, fence, /*pooledFence=*/true)) {
|
||||||
// Submit failure (device loss regime): the ended command buffer
|
// Submit failure (device loss regime): the ended command buffer
|
||||||
// stays marked recorded so Present can still try to submit it.
|
// stays marked recorded so Present can still try to submit it.
|
||||||
@@ -7457,7 +7623,7 @@ void main() {
|
|||||||
// The submitted command buffer may still be executing; recording must
|
// The submitted command buffer may still be executing; recording must
|
||||||
// restart on a fresh one. If none can be allocated, fall back to
|
// restart on a fresh one. If none can be allocated, fall back to
|
||||||
// draining this submission so reusing the buffer stays legal.
|
// draining this submission so reusing the buffer stays legal.
|
||||||
const VkResult retireResult = m_frameContext.RetireCurrentCommandBuffer();
|
const VkResult retireResult = m_frameContext.RetireCurrentCommandBuffer(submittingPreCommandBuffer);
|
||||||
if (retireResult != VK_SUCCESS) {
|
if (retireResult != VK_SUCCESS) {
|
||||||
MGLOG_E("FlushPendingCommands: RetireCurrentCommandBuffer returned %d; draining submission", retireResult);
|
MGLOG_E("FlushPendingCommands: RetireCurrentCommandBuffer returned %d; draining submission", retireResult);
|
||||||
if (vkWaitForFences(m_device, 1, &fence, VK_TRUE, UINT64_MAX) == VK_SUCCESS) {
|
if (vkWaitForFences(m_device, 1, &fence, VK_TRUE, UINT64_MAX) == VK_SUCCESS) {
|
||||||
@@ -7523,6 +7689,13 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void VulkanRenderer::OnFrameCommandRecordingBegan(VkCommandBuffer commandBuffer) {
|
void VulkanRenderer::OnFrameCommandRecordingBegan(VkCommandBuffer commandBuffer) {
|
||||||
|
// Dynamic state does not survive a command-buffer boundary.
|
||||||
|
ResetDynamicStateShadow();
|
||||||
|
// Pre-pass stream bookkeeping: a fresh frame recording references no
|
||||||
|
// textures yet.
|
||||||
|
if (m_textureManager) {
|
||||||
|
m_textureManager->AdvanceRecordingGeneration();
|
||||||
|
}
|
||||||
if (m_timerQueryManager) {
|
if (m_timerQueryManager) {
|
||||||
m_timerQueryManager->OnFrameCommandRecordingBegan(commandBuffer, m_frameContext.GetCurrentFrameIndex(),
|
m_timerQueryManager->OnFrameCommandRecordingBegan(commandBuffer, m_frameContext.GetCurrentFrameIndex(),
|
||||||
m_bufferManager.GetFrameSerial());
|
m_bufferManager.GetFrameSerial());
|
||||||
@@ -7595,6 +7768,7 @@ void main() {
|
|||||||
if (suspendedFrame.isCommandRecording) {
|
if (suspendedFrame.isCommandRecording) {
|
||||||
m_frameContext.EndCommandRecording();
|
m_frameContext.EndCommandRecording();
|
||||||
}
|
}
|
||||||
|
m_frameContext.AbandonPreCommandRecording();
|
||||||
suspendedFrame.isCommandRecording = false;
|
suspendedFrame.isCommandRecording = false;
|
||||||
suspendedFrame.hasCommandBufferRecorded = false;
|
suspendedFrame.hasCommandBufferRecorded = false;
|
||||||
m_lastPipelineValid = false;
|
m_lastPipelineValid = false;
|
||||||
@@ -7659,16 +7833,19 @@ void main() {
|
|||||||
frame.hasCommandBufferRecorded = true;
|
frame.hasCommandBufferRecorded = true;
|
||||||
m_lastPipelineValid = false; // command-buffer boundary: drop the pipeline memo
|
m_lastPipelineValid = false; // command-buffer boundary: drop the pipeline memo
|
||||||
}
|
}
|
||||||
|
m_frameContext.EndPreCommandRecordingIfOpen();
|
||||||
|
|
||||||
const Bool shouldSubmitCommandBuffer = frame.hasCommandBufferRecorded;
|
const Bool shouldSubmitCommandBuffer = frame.hasCommandBufferRecorded;
|
||||||
|
|
||||||
// 1) Submit current frame work.
|
// 1) Submit current frame work (the pre-pass stream, when recorded,
|
||||||
|
// rides the same submission strictly ahead of the frame commands).
|
||||||
auto submitPacket = m_frameContext.GetSubmitInfo(shouldSubmitCommandBuffer, m_imageIndexAcquired);
|
auto submitPacket = m_frameContext.GetSubmitInfo(shouldSubmitCommandBuffer, m_imageIndexAcquired);
|
||||||
VK_VERIFY(vkQueueSubmit(m_graphicsQueue, 1, &submitPacket.submitInfo, frame.imageInFlightFence));
|
VK_VERIFY(vkQueueSubmit(m_graphicsQueue, 1, &submitPacket.submitInfo, frame.imageInFlightFence));
|
||||||
RegisterSubmit(frame.imageInFlightFence, /*pooledFence=*/false);
|
RegisterSubmit(frame.imageInFlightFence, /*pooledFence=*/false);
|
||||||
frame.lastSubmitIndex = m_submitCounter;
|
frame.lastSubmitIndex = m_submitCounter;
|
||||||
frame.isCommandRecording = false;
|
frame.isCommandRecording = false;
|
||||||
frame.hasCommandBufferRecorded = false;
|
frame.hasCommandBufferRecorded = false;
|
||||||
|
frame.hasPreCommandBufferRecorded = false;
|
||||||
m_swapchainObject.SetImageLayout(m_imageIndexAcquired, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
m_swapchainObject.SetImageLayout(m_imageIndexAcquired, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||||
|
|
||||||
// 2) Present current frame.
|
// 2) Present current frame.
|
||||||
@@ -7696,6 +7873,13 @@ void main() {
|
|||||||
result = VK_SUCCESS;
|
result = VK_SUCCESS;
|
||||||
}
|
}
|
||||||
VK_VERIFY(result, "Present, vkQueuePresentKHR");
|
VK_VERIFY(result, "Present, vkQueuePresentKHR");
|
||||||
|
// EGL swap semantics: the presented color buffer's content is undefined the
|
||||||
|
// next time this image is acquired (EGL_BUFFER_DESTROYED, the default swap
|
||||||
|
// behaviour), and EVERY ancillary depth/stencil buffer's content is
|
||||||
|
// undefined after any swap. The render-pass manager turns the undefined
|
||||||
|
// attachments' next tile loads into LOAD_OP_DONT_CARE.
|
||||||
|
m_swapchainObject.SetImageContentDefined(m_imageIndexAcquired, false);
|
||||||
|
m_swapchainObject.SetAllDepthStencilContentUndefined();
|
||||||
// The authoritative check, done here - after the frame is presented, before the next
|
// The authoritative check, done here - after the frame is presented, before the next
|
||||||
// acquire. This is what makes a launcher-side resolution change take effect: shrinking
|
// acquire. This is what makes a launcher-side resolution change take effect: shrinking
|
||||||
// the window's buffer (SurfaceHolder.setFixedSize) moves currentExtent, the swapchain
|
// the window's buffer (SurfaceHolder.setFixedSize) moves currentExtent, the swapchain
|
||||||
@@ -8655,6 +8839,10 @@ void main() {
|
|||||||
if (m_frameContext.GetFrameCount() > 0) {
|
if (m_frameContext.GetFrameCount() > 0) {
|
||||||
m_frameContext.GetCurrent().isCommandRecording = false;
|
m_frameContext.GetCurrent().isCommandRecording = false;
|
||||||
m_frameContext.GetCurrent().hasCommandBufferRecorded = false;
|
m_frameContext.GetCurrent().hasCommandBufferRecorded = false;
|
||||||
|
// The pre-pass stream paired with the abandoned recording is
|
||||||
|
// dropped with it (its next Begin resets the buffer).
|
||||||
|
m_frameContext.GetCurrent().isPreCommandRecording = false;
|
||||||
|
m_frameContext.GetCurrent().hasPreCommandBufferRecorded = false;
|
||||||
}
|
}
|
||||||
const Bool okArena = m_bufferManager.RecreateTransientArenas(m_frameContext.GetFrameCount());
|
const Bool okArena = m_bufferManager.RecreateTransientArenas(m_frameContext.GetFrameCount());
|
||||||
MOBILEGL_ASSERT(okArena, "RecreateSwapchain: buffer manager transient arena initialization failed");
|
MOBILEGL_ASSERT(okArena, "RecreateSwapchain: buffer manager transient arena initialization failed");
|
||||||
|
|||||||
Reference in New Issue
Block a user