summaryrefslogtreecommitdiff
path: root/video.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-29 14:12:58 +1100
committerquou <quou@disroot.org>2024-12-29 14:12:58 +1100
commit4ffaf316525d95f27aa129f1842f9a22278ef929 (patch)
tree5310a62fcbcd3d17380260302079f81848b830a2 /video.cpp
parentf107689be915d96363ea75889631939c62f07980 (diff)
Don't rebind pipelines, descriptor sets and renderpasses if it isn't necessary
Diffstat (limited to 'video.cpp')
-rw-r--r--video.cpp36
1 files changed, 29 insertions, 7 deletions
diff --git a/video.cpp b/video.cpp
index d0720f5..ceb8e81 100644
--- a/video.cpp
+++ b/video.cpp
@@ -487,6 +487,11 @@ struct Context_Vk : public Context {
VkFence fence;
VkSemaphore semaphore;
+ VkPipeline last_pso;
+ VkDescriptorSet last_dso;
+ VkRenderPass last_rpo;
+ VkFramebuffer last_fbo;
+
void init_pool();
void init_cb();
void init_sync();
@@ -1830,6 +1835,8 @@ void Device::submit(Context& ctx_) {
si.pSignalSemaphores = &ctx->semaphore;*/
si.commandBufferCount = 1;
si.pCommandBuffers = &ctx->cb;
+ if (ctx->last_rpo)
+ vkCmdEndRenderPass(ctx->cb);
vkEndCommandBuffer(ctx->cb);
vkQueueSubmit(dev->queue, 1, &si, ctx->fence);
ctx->wait();
@@ -1843,6 +1850,8 @@ void Device::present() {
VkSubmitInfo si{};
VkPipelineStageFlags stage =
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
+ if (ctx->last_rpo)
+ vkCmdEndRenderPass(ctx->cb);
ctx->transition(
dev->get_backbuffer(),
Resource_State::presentable
@@ -1966,12 +1975,14 @@ void Context::submit(
dev->get_backbuffer()
);
target.state = Resource_State::render_target;
- vkCmdBindPipeline(
- ctx->cb,
- VK_PIPELINE_BIND_POINT_GRAPHICS,
- pso.pip
- );
- if (dso)
+ if (pso.pip != ctx->last_pso)
+ vkCmdBindPipeline(
+ ctx->cb,
+ VK_PIPELINE_BIND_POINT_GRAPHICS,
+ pso.pip
+ );
+ ctx->last_pso = pso.pip;
+ if (dso && dso->dset != ctx->last_dso) {
vkCmdBindDescriptorSets(
ctx->cb,
VK_PIPELINE_BIND_POINT_GRAPHICS,
@@ -1982,6 +1993,8 @@ void Context::submit(
0,
0
);
+ ctx->last_dso = dso->dset;
+ }
for (binding = draw.verts; binding->id; binding++) {
VkBuffer buf = ((Buffer_Vk*)&dev->get_buffer(binding->id))->buf;
VkDeviceSize offset = (VkDeviceSize)binding->offset;
@@ -2171,6 +2184,12 @@ std::pair<Renderpass_Vk&, Framebuffer_Vk&> Context_Vk::begin_rp(
VkClearValue clears[max_colour_attachments + 1];
int i, c = rp.colour_count, clear_count = 0;
bool has_depth = rp.depth.id;
+ if (last_rpo == rpo.rpo && last_fbo == fbo.fbo)
+ return { rpo, fbo };
+ if (last_rpo)
+ vkCmdEndRenderPass(cb);
+ last_rpo = rpo.rpo;
+ last_fbo = fbo.fbo;
for (i = 0; i < c; i++) {
VkClearValue clear{};
const auto& tar = rp.colours[i];
@@ -2203,7 +2222,6 @@ std::pair<Renderpass_Vk&, Framebuffer_Vk&> Context_Vk::begin_rp(
}
void Context_Vk::end_rp(Renderpass_Vk& rpo, Framebuffer_Vk& fbo) {
- vkCmdEndRenderPass(cb);
rpo.on_submit();
fbo.on_submit();
}
@@ -2275,6 +2293,10 @@ void Context_Vk::begin_record() {
vkResetFences(dev->dev, 1, &fence);
vkResetCommandBuffer(cb, 0);
vkBeginCommandBuffer(cb, &bi);
+ last_pso = 0;
+ last_dso = 0;
+ last_rpo = 0;
+ last_fbo = 0;
}
Context_Vk& Context_Vk::acquire(Device_Vk* device) {