Skip to content

Commit

Permalink
Dirty-track the current pipeline to avoid many vkBindPipeline calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Aug 14, 2017
1 parent 5a65334 commit a1fd2d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion GPU/Vulkan/DrawEngineVulkan.cpp
Expand Up @@ -569,6 +569,12 @@ void DrawEngineVulkan::DoFlush() {
gpuStats.numFlushes++;

VkCommandBuffer cmd = (VkCommandBuffer)draw_->GetNativeObject(Draw::NativeObject::RENDERPASS_COMMANDBUFFER);
if (cmd != lastCmd_) {
lastPipeline_ = nullptr;
lastCmd_ = cmd;
gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE);
}

VkRenderPass rp = (VkRenderPass)draw_->GetNativeObject(Draw::NativeObject::CURRENT_RENDERPASS);
if (!rp)
Crash();
Expand Down Expand Up @@ -660,7 +666,10 @@ void DrawEngineVulkan::DoFlush() {
// Already logged, let's bail out.
return;
}
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipeline); // TODO: Avoid if same as last draw.
if (pipeline != lastPipeline_) {
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipeline); // TODO: Avoid if same as last draw.
lastPipeline_ = pipeline;
}

UpdateUBOs(frame);

Expand Down
3 changes: 3 additions & 0 deletions GPU/Vulkan/DrawEngineVulkan.h
Expand Up @@ -60,6 +60,7 @@ typedef u32 ReliableHashType;

class VulkanContext;
class VulkanPushBuffer;
struct VulkanPipeline;

struct DrawEngineVulkanStats {
int pushUBOSpaceUsed;
Expand Down Expand Up @@ -146,6 +147,8 @@ class DrawEngineVulkan : public DrawEngineCommon {
// We use a single descriptor set layout for all PSP draws.
VkDescriptorSetLayout descriptorSetLayout_;
VkPipelineLayout pipelineLayout_;
VkCommandBuffer lastCmd_ = VK_NULL_HANDLE;
VulkanPipeline *lastPipeline_;

struct DescriptorSetKey {
VkImageView imageView_;
Expand Down

0 comments on commit a1fd2d1

Please sign in to comment.