Skip to content

Commit 90806f7

Browse files
committed
GPU Vulkan Display: don't recreate command buffer for mixing images
1 parent c548f2c commit 90806f7

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎GPU/GPUTracking/display/GPUDisplay.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ class GPUDisplay : public GPUDisplayInterface
297297
HighResTimer mAnimationTimer;
298298
int32_t mAnimationFrame = 0;
299299
int32_t mAnimationLastBase = 0;
300+
int32_t mAnimationMixBase = -1; // Target keyframe of the current config blend (mixing), -1 = none
300301
int32_t mAnimateScreenshot = 0;
301302
int32_t mAnimationExport = 0;
302303
bool mAnimationChangeConfig = true;

‎GPU/GPUTracking/display/backend/GPUDisplayBackendVulkan.cxx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ void GPUDisplayBackendVulkan::createCommandBuffers()
623623
allocInfo.commandPool = mCommandPool;
624624
allocInfo.level = vk::CommandBufferLevel::ePrimary;
625625
allocInfo.commandBufferCount = mImageCount;
626-
mCommandBufferUpToDate.resize(mImageCount, false);
626+
mCommandBufferUpToDate.assign(mImageCount, false);
627627
mCommandBuffers = mDevice.allocateCommandBuffers(allocInfo);
628628
mCommandBuffersText = mDevice.allocateCommandBuffers(allocInfo);
629629
mCommandBuffersTexture = mDevice.allocateCommandBuffers(allocInfo);
@@ -1471,7 +1471,7 @@ uint32_t GPUDisplayBackendVulkan::drawVertices(const vboList& v, const drawType
14711471

14721472
bool GPUDisplayBackendVulkan::prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot, bool toMixBuffer, float includeMixImage)
14731473
{
1474-
if (mDisplay->updateDrawCommands() || toMixBuffer || includeMixImage > 0) {
1474+
if (mDisplay->updateDrawCommands()) { // Main and mix command buffers stay cached while mixing, only the blend pass with the alpha value is recorded per frame
14751475
needRecordCommandBuffers();
14761476
}
14771477

@@ -1559,7 +1559,7 @@ void GPUDisplayBackendVulkan::finishDraw(bool doScreenshot, bool toMixBuffer, fl
15591559
{
15601560
if (!mCommandBufferUpToDate[mCurrentImageIndex]) {
15611561
endFillCommandBuffer(mCurrentCommandBuffer);
1562-
if (!toMixBuffer && includeMixImage == 0.f) {
1562+
if (!toMixBuffer) { // The mix pass is recorded before the main pass of the same frame, both are valid only after the latter
15631563
mCommandBufferUpToDate[mCurrentImageIndex] = true;
15641564
}
15651565
}

‎GPU/GPUTracking/display/backend/GPUDisplayBackendVulkan.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ class GPUDisplayBackendVulkan : public GPUDisplayBackend
152152
vk::PresentModeKHR mPresentMode;
153153
vk::SwapchainKHR mSwapChain;
154154
bool mMustUpdateSwapChain = false;
155-
uint8_t mSwapChainSuboptimal = 0; // Bitmasl if Last acquire / present / ... returned SUBOPTIMAL: recreate only on the first one
156-
bool mFrameSkipped = false; // No image acquired in this frame (timeout)
155+
uint8_t mSwapChainSuboptimal = 0; // Bitmask if last acquire / present / ... returned SUBOPTIMAL: recreate only on the first one
156+
bool mFrameSkipped = false; // No image acquired in this frame (timeout)
157157
void handleSwapChainResult(vk::Result retVal, uint8_t suboptimalBit);
158158
std::vector<vk::Image> mSwapChainImages;
159159
std::vector<vk::ImageView> mSwapChainImageViews;
@@ -185,7 +185,7 @@ class GPUDisplayBackendVulkan : public GPUDisplayBackend
185185
std::vector<vk::CommandBuffer> mCommandBuffersMix;
186186
std::vector<vk::CommandBuffer> mCommandBuffersPresent;
187187
std::vector<vk::CommandBufferSubmitInfo> mFrameCommandBuffers; // All command buffers of the current frame, submitted as one batch, ordered by barriers
188-
std::vector<bool> mCommandBufferUpToDate;
188+
std::vector<bool> mCommandBufferUpToDate; // Per image: main and mix command buffers recorded and still valid (cached across frames), set after the main pass of the frame
189189
std::vector<vk::Semaphore> mImageAvailableSemaphore;
190190
std::vector<vk::Semaphore> mPresentSemaphore;
191191
vk::Semaphore mTimelineSemaphore; // Signaled with an increasing value by every queue submit, replaces fences

‎GPU/GPUTracking/display/helpers/GPUDisplayAnimation.cxx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ void GPUDisplay::startAnimation()
102102
mAnimationFrame = 0;
103103
mAnimate = 1;
104104
mAnimationLastBase = 0;
105+
mAnimationMixBase = -1;
105106
}
106107

107108
int32_t GPUDisplay::animateCamera(float& animateTime, float& mixSlaveImage, hmm_mat4& nextViewMatrix)
@@ -141,7 +142,12 @@ int32_t GPUDisplay::animateCamera(float& animateTime, float& mixSlaveImage, hmm_
141142
mAnimationLastBase = base - 1;
142143
}
143144

144-
if (base != mAnimationLastBase && mAnimateVectors[0][mAnimationLastBase] != mAnimateVectors[0][base] && memcmp(&mAnimateConfig[base], &mAnimateConfig[mAnimationLastBase], sizeof(mAnimateConfig[base]))) {
145+
const bool mixing = base != mAnimationLastBase && mAnimateVectors[0][mAnimationLastBase] != mAnimateVectors[0][base] && memcmp(&mAnimateConfig[base], &mAnimateConfig[mAnimationLastBase], sizeof(mAnimateConfig[base]));
146+
if ((mixing ? base : -1) != mAnimationMixBase) { // Blended configs changed: cached (Vulkan) command buffers must be re-recorded, otherwise they are kept while mixing
147+
mAnimationMixBase = mixing ? base : -1;
148+
mUpdateDrawCommands = true;
149+
}
150+
if (mixing) {
145151
mixSlaveImage = 1.f - (time - mAnimateVectors[0][mAnimationLastBase]) / (mAnimateVectors[0][base] - mAnimateVectors[0][mAnimationLastBase]);
146152
if (mixSlaveImage > 0) {
147153
mCfgL = mAnimateConfig[mAnimationLastBase];

0 commit comments

Comments
 (0)