gfx: swapchain refactor (#3751)

* gfx: swapchain

* acquire/release/surface on swapchain

* fix swapchain texture creation

* acquire/present back on device

* formats are swapchain-specific

* swapchain: vk works

* enable device agent

* format fix

* update gfxdef

* fix enum decl

* pipeline adapt

* minor

* vk: compress attr locations directly in SPIR-V

* gles3 adjust

* InputAssembler owns an DrawInfo

* gles2 adapt

* texture keep track of its hash

* device cached states

* format

* glslang finalize

* buffer view adapt

* fg: subpass support

* minor

* 3.4 adapt

* profiler adapt

* buffer update frequency detection

* minor

* base commit

* swapchain works on metal

* spirv

* mtltexture issue

* remote test code

* depthtexture

* revert ifdef USE_METAL

* ios swapchain header

* fix some triple buffer issues

* resize accept surface transform

Co-authored-by: Zeqiang Li <Zeqiang-li@outlook.com>
This commit is contained in:
Yun Hsiao Wu
2021-08-31 19:40:32 +08:00
committed by GitHub
parent 02710af9d8
commit da2f03ff73
281 changed files with 9731 additions and 10953 deletions
+22 -12
View File
@@ -29,11 +29,14 @@
#include "VKCommands.h"
#include "VKDevice.h"
#include "VKQueue.h"
#include "vulkan/vulkan_core.h"
namespace cc {
namespace gfx {
CCVKQueue::CCVKQueue() = default;
CCVKQueue::CCVKQueue() {
_typedID = generateObjectID<decltype(this)>();
}
CCVKQueue::~CCVKQueue() {
destroy();
@@ -62,14 +65,14 @@ void CCVKQueue::submit(CommandBuffer *const *cmdBuffs, uint count) {
#endif
device->gpuBufferHub()->flush(device->gpuTransportHub());
if (!device->gpuTransportHub()->empty()) {
_gpuQueue->commandBuffers.push(device->gpuTransportHub()->packageForFlight());
if (!device->gpuTransportHub()->empty(false)) {
_gpuQueue->commandBuffers.push_back(device->gpuTransportHub()->packageForFlight(false));
}
for (uint i = 0U; i < count; ++i) {
auto *cmdBuff = static_cast<CCVKCommandBuffer *>(cmdBuffs[i]);
if (!cmdBuff->_pendingQueue.empty()) {
_gpuQueue->commandBuffers.push(cmdBuff->_pendingQueue.front());
_gpuQueue->commandBuffers.push_back(cmdBuff->_pendingQueue.front());
cmdBuff->_pendingQueue.pop();
_numDrawCalls += cmdBuff->_numDrawCalls;
@@ -78,20 +81,27 @@ void CCVKQueue::submit(CommandBuffer *const *cmdBuffs, uint count) {
}
}
if (!device->gpuTransportHub()->empty(true)) {
_gpuQueue->commandBuffers.push_back(device->gpuTransportHub()->packageForFlight(true));
}
size_t waitSemaphoreCount = _gpuQueue->lastSignaledSemaphores.size();
VkSemaphore signal = waitSemaphoreCount ? device->gpuSemaphorePool()->alloc() : VK_NULL_HANDLE;
_gpuQueue->submitStageMasks.resize(waitSemaphoreCount, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
VkSubmitInfo submitInfo{VK_STRUCTURE_TYPE_SUBMIT_INFO};
submitInfo.waitSemaphoreCount = _gpuQueue->nextWaitSemaphore ? 1 : 0;
submitInfo.pWaitSemaphores = &_gpuQueue->nextWaitSemaphore;
submitInfo.pWaitDstStageMask = &_gpuQueue->submitStageMask;
submitInfo.commandBufferCount = _gpuQueue->commandBuffers.size();
submitInfo.waitSemaphoreCount = utils::toUint(waitSemaphoreCount);
submitInfo.pWaitSemaphores = _gpuQueue->lastSignaledSemaphores.data();
submitInfo.pWaitDstStageMask = _gpuQueue->submitStageMasks.data();
submitInfo.commandBufferCount = utils::toUint(_gpuQueue->commandBuffers.size());
submitInfo.pCommandBuffers = &_gpuQueue->commandBuffers[0];
submitInfo.signalSemaphoreCount = _gpuQueue->nextSignalSemaphore ? 1 : 0;
submitInfo.pSignalSemaphores = &_gpuQueue->nextSignalSemaphore;
submitInfo.signalSemaphoreCount = waitSemaphoreCount ? 1 : 0;
submitInfo.pSignalSemaphores = &signal;
VkFence vkFence = device->gpuFencePool()->alloc();
VK_CHECK(vkQueueSubmit(_gpuQueue->vkQueue, 1, &submitInfo, vkFence));
_gpuQueue->nextWaitSemaphore = _gpuQueue->nextSignalSemaphore;
_gpuQueue->nextSignalSemaphore = device->gpuSemaphorePool()->alloc();
_gpuQueue->lastSignaledSemaphores.assign(1, signal);
}
} // namespace gfx