From c4ccf5b7348aadbf67e3a2eaa79be67627c82cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 15 Aug 2017 12:02:47 +0200 Subject: [PATCH] Simple micro-optimization in AdvanceVerts --- GPU/GPUCommon.cpp | 14 -------------- GPU/GPUCommon.h | 11 +++++++++-- GPU/Vulkan/DrawEngineVulkan.cpp | 6 +++--- GPU/Vulkan/StateMappingVulkan.cpp | 7 ++++++- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 51971c695f..b29d8370cc 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -2253,20 +2253,6 @@ void GPUCommon::SetCmdValue(u32 op) { ExecuteOp(op, diff); } -void GPUCommon::AdvanceVerts(u32 vertType, int count, int bytesRead) { - if ((vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { - int indexSize = 1; - if ((vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT) - indexSize = 2; - else if ((vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_32BIT) - indexSize = 4; - gstate_c.indexAddr += count * indexSize; - } else { - gstate_c.vertexAddr += bytesRead; - } -} - - void GPUCommon::DoBlockTransfer(u32 skipDrawReason) { // TODO: This is used a lot to copy data around between render targets and textures, // and also to quickly load textures from RAM to VRAM. So we should do checks like the following: diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index a739672d5f..ca2d8ac931 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -233,7 +233,7 @@ protected: lastDraw_ = type; } // Prim == RECTANGLES can cause CanUseHardwareTransform to flip, so we need to dirty. - // Also, culling may be affected. + // Also, culling may be affected so dirty the raster state. if ((prim == GE_PRIM_RECTANGLES) != (lastPrim_ == GE_PRIM_RECTANGLES)) { gstate_c.Dirty(DIRTY_RASTER_STATE | DIRTY_VERTEXSHADER_STATE); lastPrim_ = prim; @@ -266,7 +266,14 @@ protected: void DoBlockTransfer(u32 skipDrawReason); - void AdvanceVerts(u32 vertType, int count, int bytesRead); + void AdvanceVerts(u32 vertType, int count, int bytesRead) { + if ((vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { + int indexShift = ((vertType & GE_VTYPE_IDX_MASK) >> GE_VTYPE_IDX_SHIFT) - 1; + gstate_c.indexAddr += count << indexShift; + } else { + gstate_c.vertexAddr += bytesRead; + } + } void PerformMemoryCopyInternal(u32 dest, u32 src, int size); void PerformMemorySetInternal(u32 dest, u8 v, int size); diff --git a/GPU/Vulkan/DrawEngineVulkan.cpp b/GPU/Vulkan/DrawEngineVulkan.cpp index 42998136c6..049ec4a8c8 100644 --- a/GPU/Vulkan/DrawEngineVulkan.cpp +++ b/GPU/Vulkan/DrawEngineVulkan.cpp @@ -479,7 +479,7 @@ VkDescriptorSet DrawEngineVulkan::GetDescriptorSet(VkImageView imageView, VkSamp memset(writes, 0, sizeof(writes)); // Main texture int n = 0; - VkDescriptorImageInfo tex; + VkDescriptorImageInfo tex{}; if (imageView) { // TODO: Also support LAYOUT_GENERAL to be able to texture from framebuffers without transitioning them? tex.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; @@ -499,7 +499,7 @@ VkDescriptorSet DrawEngineVulkan::GetDescriptorSet(VkImageView imageView, VkSamp // Tessellation data textures if (gstate_c.bezier || gstate_c.spline) { - VkDescriptorImageInfo tess_tex[3]; + VkDescriptorImageInfo tess_tex[3]{}; VkSampler sampler = ((TessellationDataTransferVulkan *)tessDataTransfer)->GetSampler(); for (int i = 0; i < 3; i++) { VulkanTexture *texture = ((TessellationDataTransferVulkan *)tessDataTransfer)->GetTexture(i); @@ -521,7 +521,7 @@ VkDescriptorSet DrawEngineVulkan::GetDescriptorSet(VkImageView imageView, VkSamp } // Uniform buffer objects - VkDescriptorBufferInfo buf[3]; + VkDescriptorBufferInfo buf[3]{}; int count = 0; buf[count].buffer = base; buf[count].offset = 0; diff --git a/GPU/Vulkan/StateMappingVulkan.cpp b/GPU/Vulkan/StateMappingVulkan.cpp index 821c4b1466..30abd4e054 100644 --- a/GPU/Vulkan/StateMappingVulkan.cpp +++ b/GPU/Vulkan/StateMappingVulkan.cpp @@ -130,6 +130,12 @@ void ResetShaderBlending() { // In Vulkan, we simply collect all the state together into a "pipeline key" - we don't actually set any state here // (the caller is responsible for setting the little dynamic state that is supported, dynState). void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManager, ShaderManagerVulkan *shaderManager, int prim, VulkanPipelineRasterStateKey &key, VulkanDynamicState &dynState) { + /* + if (!gstate_c.IsDirty(DIRTY_BLEND_STATE | DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_DEPTHRANGE | DIRTY_RASTER_STATE)) { + // nothing to do + return; + }*/ + bool useBufferedRendering = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; if (gstate_c.IsDirty(DIRTY_BLEND_STATE)) { @@ -151,7 +157,6 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag bool colorMask = gstate.isClearModeColorMask(); bool alphaMask = gstate.isClearModeAlphaMask(); key.colorWriteMask = (colorMask ? (VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT) : 0) | (alphaMask ? VK_COLOR_COMPONENT_A_BIT : 0); - } else { key.logicOpEnable = false; key.logicOp = VK_LOGIC_OP_CLEAR;