diff --git a/GPU/GLES/FramebufferManagerGLES.cpp b/GPU/GLES/FramebufferManagerGLES.cpp index 6dede8ff5b..1ec5a83c95 100644 --- a/GPU/GLES/FramebufferManagerGLES.cpp +++ b/GPU/GLES/FramebufferManagerGLES.cpp @@ -226,7 +226,6 @@ void FramebufferManagerGLES::Init() { // Workaround for upscaling shaders where we force x1 resolution without saving it Resized(); CompileDraw2DProgram(); - SetLineWidth(); } void FramebufferManagerGLES::SetTextureCache(TextureCacheGLES *tc) { @@ -449,18 +448,6 @@ void FramebufferManagerGLES::RebindFramebuffer() { glstate.viewport.restore(); } -void FramebufferManagerGLES::SetLineWidth() { -#ifndef USING_GLES2 - if (g_Config.iInternalResolution == 0) { - glLineWidth(std::max(1, (int)(renderWidth_ / 480))); - glPointSize(std::max(1.0f, (float)(renderWidth_ / 480.f))); - } else { - glLineWidth(g_Config.iInternalResolution); - glPointSize((float)g_Config.iInternalResolution); - } -#endif -} - void FramebufferManagerGLES::ReformatFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old) { if (!useBufferedRendering_ || !vfb->fbo) { return; @@ -1064,7 +1051,16 @@ void FramebufferManagerGLES::Resized() { } DestroyDraw2DProgram(); - SetLineWidth(); + +#ifndef USING_GLES2 + if (g_Config.iInternalResolution == 0) { + glLineWidth(std::max(1, (int)(renderWidth_ / 480))); + glPointSize(std::max(1.0f, (float)(renderWidth_ / 480.f))); + } else { + glLineWidth(g_Config.iInternalResolution); + glPointSize((float)g_Config.iInternalResolution); + } +#endif if (!draw2dprogram_) { CompileDraw2DProgram(); diff --git a/GPU/Vulkan/DrawEngineVulkan.cpp b/GPU/Vulkan/DrawEngineVulkan.cpp index a6022747fb..4d5c5930ce 100644 --- a/GPU/Vulkan/DrawEngineVulkan.cpp +++ b/GPU/Vulkan/DrawEngineVulkan.cpp @@ -509,6 +509,10 @@ void DrawEngineVulkan::DecodeVerts(VulkanPushBuffer *push, uint32_t *bindOffset, } } +void DrawEngineVulkan::SetLineWidth(float lineWidth) { + pipelineManager_->SetLineWidth(lineWidth); +} + VkDescriptorSet DrawEngineVulkan::GetOrCreateDescriptorSet(VkImageView imageView, VkSampler sampler, VkBuffer base, VkBuffer light, VkBuffer bone) { DescriptorSetKey key; key.imageView_ = imageView; @@ -517,12 +521,15 @@ VkDescriptorSet DrawEngineVulkan::GetOrCreateDescriptorSet(VkImageView imageView key.base_ = base; key.light_ = light; key.bone_ = bone; - assert(base != VK_NULL_HANDLE); - assert(light != VK_NULL_HANDLE); - assert(bone != VK_NULL_HANDLE); + _dbg_assert_(G3D, base != VK_NULL_HANDLE); + _dbg_assert_(G3D, light != VK_NULL_HANDLE); + _dbg_assert_(G3D, bone != VK_NULL_HANDLE); + + bool tess = gstate_c.bezier || gstate_c.spline; FrameData *frame = &frame_[vulkan_->GetCurFrame()]; - if (!gstate_c.bezier && !gstate_c.spline) { // Has no cache when HW tessellation. + // See if we already have this descriptor set cached. + if (!tess) { // Don't cache descriptors for HW tessellation. VkDescriptorSet d = frame->descSets.Get(key); if (d != VK_NULL_HANDLE) return d; @@ -580,7 +587,7 @@ VkDescriptorSet DrawEngineVulkan::GetOrCreateDescriptorSet(VkImageView imageView // Skipping 2nd texture for now. // Tessellation data textures - if (gstate_c.bezier || gstate_c.spline) { + if (tess) { VkDescriptorImageInfo tess_tex[3]{}; VkSampler sampler = ((TessellationDataTransferVulkan *)tessDataTransfer)->GetSampler(); for (int i = 0; i < 3; i++) { diff --git a/GPU/Vulkan/DrawEngineVulkan.h b/GPU/Vulkan/DrawEngineVulkan.h index 48641131dc..b91993e998 100644 --- a/GPU/Vulkan/DrawEngineVulkan.h +++ b/GPU/Vulkan/DrawEngineVulkan.h @@ -175,6 +175,8 @@ public: return stats_; } + void SetLineWidth(float lineWidth); + private: struct FrameData; void ApplyDrawStateLate(VulkanRenderManager *renderManager, bool applyStencilRef, uint8_t stencilRef, bool useBlendConstant); diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index 5a60a9bcbd..8eeb0d33fb 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -158,6 +158,9 @@ GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw) UpdateVsyncInterval(true); textureCacheVulkan_->NotifyConfigChanged(); + if (vulkan_->GetFeaturesEnabled().wideLines) { + drawEngine_.SetLineWidth(PSP_CoreParameter().renderWidth / 480.0f); + } } GPU_Vulkan::~GPU_Vulkan() { @@ -221,6 +224,9 @@ void GPU_Vulkan::BeginHostFrame() { framebufferManager_->Resized(); drawEngine_.Resized(); textureCacheVulkan_->NotifyConfigChanged(); + if (vulkan_->GetFeaturesEnabled ().wideLines) { + drawEngine_.SetLineWidth(PSP_CoreParameter().renderWidth / 480.0f); + } } resized_ = false; diff --git a/GPU/Vulkan/PipelineManagerVulkan.cpp b/GPU/Vulkan/PipelineManagerVulkan.cpp index 277d7ffe0f..940254e7d1 100644 --- a/GPU/Vulkan/PipelineManagerVulkan.cpp +++ b/GPU/Vulkan/PipelineManagerVulkan.cpp @@ -121,7 +121,7 @@ static bool UsesBlendConstant(int factor) { static VulkanPipeline *CreateVulkanPipeline(VkDevice device, VkPipelineCache pipelineCache, VkPipelineLayout layout, VkRenderPass renderPass, const VulkanPipelineRasterStateKey &key, - const VertexDecoder *vtxDec, VulkanVertexShader *vs, VulkanFragmentShader *fs, bool useHwTransform) { + const VertexDecoder *vtxDec, VulkanVertexShader *vs, VulkanFragmentShader *fs, bool useHwTransform, float lineWidth) { bool useBlendConstant = false; VkPipelineColorBlendAttachmentState blend0 = {}; @@ -188,7 +188,7 @@ static VulkanPipeline *CreateVulkanPipeline(VkDevice device, VkPipelineCache pip rs.depthBiasEnable = false; rs.cullMode = key.cullMode; rs.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; - rs.lineWidth = 1.0f; + rs.lineWidth = lineWidth; rs.rasterizerDiscardEnable = false; rs.polygonMode = VK_POLYGON_MODE_FILL; rs.depthClampEnable = false; @@ -289,6 +289,7 @@ static VulkanPipeline *CreateVulkanPipeline(VkDevice device, VkPipelineCache pip vulkanPipeline->pipeline = pipeline; vulkanPipeline->uniformBlocks = UB_VS_FS_BASE; vulkanPipeline->useBlendConstant = useBlendConstant; + vulkanPipeline->usesLines = key.topology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST || key.topology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP; if (useHwTransform) { if (vs->HasLights()) { vulkanPipeline->uniformBlocks |= UB_VS_LIGHTS; @@ -320,7 +321,7 @@ VulkanPipeline *PipelineManagerVulkan::GetOrCreatePipeline(VkPipelineLayout layo VulkanPipeline *pipeline = CreateVulkanPipeline( vulkan_->GetDevice(), pipelineCache_, layout, renderPass, - rasterKey, vtxDec, vs, fs, useHwTransform); + rasterKey, vtxDec, vs, fs, useHwTransform, lineWidth_); // Even if the result is nullptr, insert it so we don't try to create it repeatedly. pipelines_.Insert(key, pipeline); return pipeline; @@ -370,3 +371,18 @@ std::string PipelineManagerVulkan::DebugGetObjectString(std::string id, DebugSha return "N/A"; } } + +void PipelineManagerVulkan::SetLineWidth(float lineWidth) { + if (lineWidth_ == lineWidth) + return; + lineWidth_ = lineWidth; + + // Wipe all line-drawing pipelines. + pipelines_.Iterate([&](const VulkanPipelineKey &key, VulkanPipeline *value) { + if (value->usesLines) { + vulkan_->Delete().QueueDeletePipeline(value->pipeline); + delete value; + pipelines_.Remove(key); + } + }); +} \ No newline at end of file diff --git a/GPU/Vulkan/PipelineManagerVulkan.h b/GPU/Vulkan/PipelineManagerVulkan.h index 15e29864f1..9387ed43fe 100644 --- a/GPU/Vulkan/PipelineManagerVulkan.h +++ b/GPU/Vulkan/PipelineManagerVulkan.h @@ -65,6 +65,7 @@ struct VulkanPipeline { VkPipeline pipeline; int uniformBlocks; // UB_ enum above. bool useBlendConstant; + bool usesLines; }; class VulkanContext; @@ -81,6 +82,8 @@ public: void Clear(); + void SetLineWidth(float lw); + void DeviceLost(); void DeviceRestore(VulkanContext *vulkan); @@ -91,4 +94,5 @@ private: DenseHashMap pipelines_; VkPipelineCache pipelineCache_; VulkanContext *vulkan_; + float lineWidth_ = 1.0f; };