diff --git a/core/rend/gles/glcache.h b/core/rend/gles/glcache.h index 3029beea6..341662acb 100644 --- a/core/rend/gles/glcache.h +++ b/core/rend/gles/glcache.h @@ -164,6 +164,7 @@ public: void Reset() { _texture = 0xFFFFFFFFu; + _texture_params.clear(); _src_blend_factor = 0xFFFFFFFFu; _dst_blend_factor = 0xFFFFFFFFu; _clear_r = -1.f; diff --git a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp index 5127d85fa..1c6c1c73e 100644 --- a/core/rend/gles/gles.cpp +++ b/core/rend/gles/gles.cpp @@ -1234,9 +1234,6 @@ bool RenderFrame() glClear(GL_COLOR_BUFFER_BIT); DrawFramebuffer(); } - #ifdef _WIN32 - //Sleep(40); //to test MT stability - #endif eglCheck(); @@ -1274,7 +1271,7 @@ struct glesrend : Renderer return !pvrrc.isRTT; } bool RenderLastFrame() override { return !theGLContext.IsSwapBufferPreserved() ? render_output_framebuffer() : false; } - void Present() override { theGLContext.Swap(); glViewport(0, 0, screen_width, screen_height); } + void Present() override { theGLContext.Swap(); } void DrawOSD(bool clear_screen) override { diff --git a/core/rend/vulkan/commandpool.h b/core/rend/vulkan/commandpool.h index 42557ea0a..8c6955a2f 100644 --- a/core/rend/vulkan/commandpool.h +++ b/core/rend/vulkan/commandpool.h @@ -58,7 +58,7 @@ public: void EndFrame() { - std::vector commandBuffers = GetInFlightCommandBuffers(); + std::vector commandBuffers = vk::uniqueToRaw(inFlightBuffers[index]); VulkanContext::Instance()->GetGraphicsQueue().submit( vk::SubmitInfo(0, nullptr, nullptr, commandBuffers.size(), commandBuffers.data()), *fences[index]); } @@ -70,11 +70,8 @@ public: VulkanContext::Instance()->GetDevice().resetFences(1, &fences[index].get()); std::vector& inFlight = inFlightBuffers[index]; std::vector& freeBuf = freeBuffers[index]; - while (!inFlight.empty()) - { - freeBuf.emplace_back(std::move(inFlight.back())); - inFlight.pop_back(); - } + std::move(inFlight.begin(), inFlight.end(), std::back_inserter(freeBuf)); + inFlight.clear(); VulkanContext::Instance()->GetDevice().resetCommandPool(*commandPools[index], vk::CommandPoolResetFlagBits::eReleaseResources); } @@ -100,17 +97,6 @@ public: } private: - std::vector GetInFlightCommandBuffers() const - { - const auto& buffers = inFlightBuffers[index]; - std::vector v; - v.reserve(buffers.size()); - std::for_each(buffers.begin(), buffers.end(), - [&v](const vk::UniqueCommandBuffer& cmdBuf) { v.push_back(*cmdBuf); }); - - return v; - } - int index = 0; std::vector> freeBuffers; std::vector> inFlightBuffers; diff --git a/core/rend/vulkan/drawer.cpp b/core/rend/vulkan/drawer.cpp index 51ab3e62d..4dbdbbf9c 100644 --- a/core/rend/vulkan/drawer.cpp +++ b/core/rend/vulkan/drawer.cpp @@ -205,7 +205,7 @@ void Drawer::DrawList(const vk::CommandBuffer& cmdBuffer, u32 listType, bool sor void Drawer::DrawModVols(const vk::CommandBuffer& cmdBuffer, int first, int count) { - if (count == 0 || pvrrc.modtrig.used() == 0) + if (count == 0 || pvrrc.modtrig.used() == 0 || !settings.rend.ModifierVolumes) return; vk::Buffer buffer = GetMainBuffer(0)->buffer.get(); @@ -452,6 +452,7 @@ vk::CommandBuffer TextureDrawer::BeginRenderPass() else { colorImageCurrentLayout = vk::ImageLayout::eShaderReadOnlyOptimal; + setImageLayout(commandBuffer, *texture->image, vk::Format::eR8G8B8A8Unorm, 1, colorImageCurrentLayout, vk::ImageLayout::eColorAttachmentOptimal); } colorImage = *texture->image; colorImageView = texture->GetImageView(); @@ -474,8 +475,6 @@ vk::CommandBuffer TextureDrawer::BeginRenderPass() width = widthPow2; height = heightPow2; - setImageLayout(commandBuffer, colorImage, vk::Format::eR8G8B8A8Unorm, 1, colorImageCurrentLayout, vk::ImageLayout::eColorAttachmentOptimal); - vk::ImageView imageViews[] = { colorImageView, depthAttachment->GetImageView(), @@ -543,15 +542,101 @@ void TextureDrawer::EndRenderPass() texture->lock_block = libCore_vramlock_Lock(texture->sa_tex, texture->sa + texture->size - 1, texture); } +void ScreenDrawer::Init(SamplerManager *samplerManager, ShaderManager *shaderManager) +{ + this->shaderManager = shaderManager; + currentScreenScaling = settings.rend.ScreenScaling; + viewport = GetContext()->GetViewPort(); + viewport.width = lroundf(viewport.width * currentScreenScaling / 100.f); + viewport.height = lroundf(viewport.height * currentScreenScaling / 100.f); + depthAttachment = std::unique_ptr( + new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice())); + depthAttachment->Init(viewport.width, viewport.height, GetContext()->GetDepthFormat(), vk::ImageUsageFlagBits::eDepthStencilAttachment); + + if (!renderPass) + { + vk::AttachmentDescription attachmentDescriptions[] = { + // Color attachment + vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), GetContext()->GetColorFormat(), vk::SampleCountFlagBits::e1, + vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eStore, + vk::AttachmentLoadOp::eDontCare, vk::AttachmentStoreOp::eDontCare, + vk::ImageLayout::eUndefined, vk::ImageLayout::eShaderReadOnlyOptimal), + // Depth attachment + vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), GetContext()->GetDepthFormat(), vk::SampleCountFlagBits::e1, + vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eDontCare, + vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eDontCare, + vk::ImageLayout::eUndefined, vk::ImageLayout::eDepthStencilAttachmentOptimal), + }; + vk::AttachmentReference colorReference(0, vk::ImageLayout::eColorAttachmentOptimal); + vk::AttachmentReference depthReference(1, vk::ImageLayout::eDepthStencilAttachmentOptimal); + + vk::SubpassDescription subpasses[] = { + vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, + 0, nullptr, + 1, &colorReference, + nullptr, + &depthReference), + }; + + std::vector dependencies; + dependencies.emplace_back(0, VK_SUBPASS_EXTERNAL, vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::PipelineStageFlagBits::eFragmentShader, + vk::AccessFlagBits::eColorAttachmentWrite, vk::AccessFlagBits::eShaderRead, vk::DependencyFlagBits::eByRegion); + + renderPass = GetContext()->GetDevice().createRenderPassUnique(vk::RenderPassCreateInfo(vk::RenderPassCreateFlags(), + ARRAY_SIZE(attachmentDescriptions), attachmentDescriptions, + ARRAY_SIZE(subpasses), subpasses, + dependencies.size(), dependencies.data())); + } + size_t size = VulkanContext::Instance()->GetSwapChainSize(); + if (colorAttachments.size() > size) + { + colorAttachments.resize(size); + framebuffers.resize(size); + } + else + { + vk::ImageView attachments[] = { + nullptr, + depthAttachment->GetImageView(), + }; + while (colorAttachments.size() < size) + { + colorAttachments.push_back(std::unique_ptr( + new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice()))); + colorAttachments.back()->Init(viewport.width, viewport.height, GetContext()->GetColorFormat(), + vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eSampled); + attachments[0] = colorAttachments.back()->GetImageView(); + vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), *renderPass, + ARRAY_SIZE(attachments), attachments, viewport.width, viewport.height, 1); + framebuffers.push_back(GetContext()->GetDevice().createFramebufferUnique(createInfo)); + } + } + + if (!screenPipelineManager) + screenPipelineManager = std::unique_ptr(new PipelineManager()); + screenPipelineManager->Init(shaderManager, *renderPass); + Drawer::Init(samplerManager, screenPipelineManager.get()); + + if (descriptorSets.size() > GetContext()->GetSwapChainSize()) + descriptorSets.resize(GetContext()->GetSwapChainSize()); + else + while (descriptorSets.size() < GetContext()->GetSwapChainSize()) + { + descriptorSets.push_back(DescriptorSets()); + descriptorSets.back().Init(samplerManager, screenPipelineManager->GetPipelineLayout(), screenPipelineManager->GetPerFrameDSLayout(), screenPipelineManager->GetPerPolyDSLayout()); + } +} + vk::CommandBuffer ScreenDrawer::BeginRenderPass() { if (currentScreenScaling != settings.rend.ScreenScaling) Init(samplerManager, shaderManager); + imageIndex = (imageIndex + 1) % GetContext()->GetSwapChainSize(); vk::CommandBuffer commandBuffer = commandPool->Allocate(); commandBuffer.begin(vk::CommandBufferBeginInfo(vk::CommandBufferUsageFlagBits::eOneTimeSubmit)); const vk::ClearValue clear_colors[] = { vk::ClearColorValue(std::array { 0.f, 0.f, 0.f, 1.f }), vk::ClearDepthStencilValue { 0.f, 0 } }; - commandBuffer.beginRenderPass(vk::RenderPassBeginInfo(*renderPass, *framebuffer, + commandBuffer.beginRenderPass(vk::RenderPassBeginInfo(*renderPass, *framebuffers[imageIndex], vk::Rect2D( { 0, 0 }, viewport), 2, clear_colors), vk::SubpassContents::eInline); commandBuffer.setViewport(0, vk::Viewport(0.0f, 0.0f, viewport.width, viewport.height, 1.0f, 0.0f)); @@ -568,6 +653,7 @@ void ScreenDrawer::EndRenderPass() { currentCommandBuffer.endRenderPass(); currentCommandBuffer.end(); + currentCommandBuffer = nullptr; commandPool->EndFrame(); - GetContext()->PresentFrame(colorAttachment->GetImageView(), vk::Offset2D(viewport.width, viewport.height)); + GetContext()->PresentFrame(colorAttachments[imageIndex]->GetImageView(), vk::Offset2D(viewport.width, viewport.height)); } diff --git a/core/rend/vulkan/drawer.h b/core/rend/vulkan/drawer.h index 7d51dc790..d76d9936d 100644 --- a/core/rend/vulkan/drawer.h +++ b/core/rend/vulkan/drawer.h @@ -40,6 +40,7 @@ public: currentScissor = scissor; } } + void SetCommandPool(CommandPool *commandPool) { this->commandPool = commandPool; } protected: VulkanContext *GetContext() const { return VulkanContext::Instance(); } @@ -91,21 +92,16 @@ protected: vk::Rect2D baseScissor; vk::Rect2D currentScissor; TransformMatrix matrices; + CommandPool *commandPool = nullptr; }; class Drawer : public BaseDrawer { public: - Drawer() = default; virtual ~Drawer() = default; bool Draw(const Texture *fogTexture); - Drawer(const Drawer& other) = delete; - Drawer(Drawer&& other) = default; - Drawer& operator=(const Drawer& other) = delete; - Drawer& operator=(Drawer&& other) = default; virtual vk::CommandBuffer BeginRenderPass() = 0; virtual void EndRenderPass() = 0; - void SetCommandPool(CommandPool *commandPool) { this->commandPool = commandPool; } protected: void Init(SamplerManager *samplerManager, PipelineManager *pipelineManager) @@ -119,7 +115,6 @@ protected: PipelineManager *pipelineManager = nullptr; vk::CommandBuffer currentCommandBuffer; SamplerManager *samplerManager = nullptr; - CommandPool *commandPool = nullptr; private: void SortTriangles(); @@ -144,87 +139,12 @@ private: class ScreenDrawer : public Drawer { public: - void Init(SamplerManager *samplerManager, ShaderManager *shaderManager) - { - this->shaderManager = shaderManager; - currentScreenScaling = settings.rend.ScreenScaling; - viewport = GetContext()->GetViewPort(); - viewport.width = lroundf(viewport.width * currentScreenScaling / 100.f); - viewport.height = lroundf(viewport.height * currentScreenScaling / 100.f); - depthAttachment = std::unique_ptr( - new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice())); - depthAttachment->Init(viewport.width, viewport.height, GetContext()->GetDepthFormat(), vk::ImageUsageFlagBits::eDepthStencilAttachment); - colorAttachment = std::unique_ptr( - new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice())); - colorAttachment->Init(viewport.width, viewport.height, GetContext()->GetColorFormat(), - vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eSampled); - - if (!renderPass) - { - vk::AttachmentDescription attachmentDescriptions[] = { - // Color attachment - vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), GetContext()->GetColorFormat(), vk::SampleCountFlagBits::e1, - vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eStore, - vk::AttachmentLoadOp::eDontCare, vk::AttachmentStoreOp::eDontCare, - vk::ImageLayout::eUndefined, vk::ImageLayout::eShaderReadOnlyOptimal), - // Depth attachment - vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), GetContext()->GetDepthFormat(), vk::SampleCountFlagBits::e1, - vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eDontCare, - vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eDontCare, - vk::ImageLayout::eUndefined, vk::ImageLayout::eDepthStencilAttachmentOptimal), - }; - vk::AttachmentReference colorReference(0, vk::ImageLayout::eColorAttachmentOptimal); - vk::AttachmentReference depthReference(1, vk::ImageLayout::eDepthStencilAttachmentOptimal); - - vk::SubpassDescription subpasses[] = { - vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, - 0, nullptr, - 1, &colorReference, - nullptr, - &depthReference), - }; - - std::vector dependencies; - dependencies.emplace_back(0, VK_SUBPASS_EXTERNAL, vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::PipelineStageFlagBits::eFragmentShader, - vk::AccessFlagBits::eColorAttachmentWrite, vk::AccessFlagBits::eShaderRead, vk::DependencyFlagBits::eByRegion); - - renderPass = GetContext()->GetDevice().createRenderPassUnique(vk::RenderPassCreateInfo(vk::RenderPassCreateFlags(), - ARRAY_SIZE(attachmentDescriptions), attachmentDescriptions, - ARRAY_SIZE(subpasses), subpasses, - dependencies.size(), dependencies.data())); - } - vk::ImageView attachments[] = { - colorAttachment->GetImageView(), - depthAttachment->GetImageView(), - }; - vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), *renderPass, - ARRAY_SIZE(attachments), attachments, viewport.width, viewport.height, 1); - framebuffer = GetContext()->GetDevice().createFramebufferUnique(createInfo); - - if (!screenPipelineManager) - screenPipelineManager = std::unique_ptr(new PipelineManager()); - screenPipelineManager->Init(shaderManager, *renderPass); - Drawer::Init(samplerManager, screenPipelineManager.get()); - - if (descriptorSets.size() > GetContext()->GetSwapChainSize()) - descriptorSets.resize(GetContext()->GetSwapChainSize()); - else - while (descriptorSets.size() < GetContext()->GetSwapChainSize()) - { - descriptorSets.push_back(DescriptorSets()); - descriptorSets.back().Init(samplerManager, screenPipelineManager->GetPipelineLayout(), screenPipelineManager->GetPerFrameDSLayout(), screenPipelineManager->GetPerPolyDSLayout()); - } - } - - ScreenDrawer() = default; - ScreenDrawer(const ScreenDrawer& other) = delete; - ScreenDrawer(ScreenDrawer&& other) = default; - ScreenDrawer& operator=(const ScreenDrawer& other) = delete; - ScreenDrawer& operator=(ScreenDrawer&& other) = default; - virtual vk::CommandBuffer BeginRenderPass() override; + void Init(SamplerManager *samplerManager, ShaderManager *shaderManager); virtual void EndRenderPass() override; + vk::RenderPass GetRenderPass() const { return *renderPass; } protected: + virtual vk::CommandBuffer BeginRenderPass() override; virtual DescriptorSets& GetCurrentDescSet() override { return descriptorSets[GetCurrentImage()]; } virtual BufferData* GetMainBuffer(u32 size) override { @@ -247,19 +167,20 @@ protected: }; private: - int GetCurrentImage() { return GetContext()->GetCurrentImageIndex(); } + int GetCurrentImage() { return imageIndex; } std::vector descriptorSets; std::vector> mainBuffers; std::unique_ptr screenPipelineManager; vk::UniqueRenderPass renderPass; - vk::UniqueFramebuffer framebuffer; - std::unique_ptr colorAttachment; + std::vector framebuffers; + std::vector> colorAttachments; std::unique_ptr depthAttachment; vk::Extent2D viewport; int currentScreenScaling = 0; ShaderManager *shaderManager = nullptr; + int imageIndex = 0; }; class TextureDrawer : public Drawer @@ -273,11 +194,6 @@ public: this->textureCache = textureCache; } - TextureDrawer() = default; - TextureDrawer(const TextureDrawer& other) = delete; - TextureDrawer(TextureDrawer&& other) = default; - TextureDrawer& operator=(const TextureDrawer& other) = delete; - TextureDrawer& operator=(TextureDrawer&& other) = default; virtual void EndRenderPass() override; protected: diff --git a/core/rend/vulkan/oit_drawer.cpp b/core/rend/vulkan/oit_drawer.cpp index 8f468286f..3604a9f52 100644 --- a/core/rend/vulkan/oit_drawer.cpp +++ b/core/rend/vulkan/oit_drawer.cpp @@ -90,7 +90,7 @@ void OITDrawer::DrawList(const vk::CommandBuffer& cmdBuffer, u32 listType, bool template void OITDrawer::DrawModifierVolumes(const vk::CommandBuffer& cmdBuffer, int first, int count) { - if (count == 0 || pvrrc.modtrig.used() == 0) + if (count == 0 || pvrrc.modtrig.used() == 0 || !settings.rend.ModifierVolumes) return; vk::Buffer buffer = GetMainBuffer(0)->buffer.get(); @@ -501,8 +501,7 @@ vk::CommandBuffer OITTextureDrawer::NewFrame() { if (!colorAttachment) { - colorAttachment = std::unique_ptr( - new FramebufferAttachment(context->GetPhysicalDevice(), device)); + colorAttachment = std::unique_ptr(new FramebufferAttachment(context->GetPhysicalDevice(), device)); } colorAttachment->Init(widthPow2, heightPow2, vk::Format::eR8G8B8A8Unorm, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc); diff --git a/core/rend/vulkan/oit_drawer.h b/core/rend/vulkan/oit_drawer.h index 96281702c..ce1198bbd 100644 --- a/core/rend/vulkan/oit_drawer.h +++ b/core/rend/vulkan/oit_drawer.h @@ -35,17 +35,11 @@ class OITDrawer : public BaseDrawer { public: - OITDrawer() = default; virtual ~OITDrawer() = default; bool Draw(const Texture *fogTexture); - OITDrawer(const OITDrawer& other) = delete; - OITDrawer(OITDrawer&& other) = default; - OITDrawer& operator=(const OITDrawer& other) = delete; - OITDrawer& operator=(OITDrawer&& other) = default; virtual vk::CommandBuffer NewFrame() = 0; virtual void EndFrame() = 0; - void SetCommandPool(CommandPool *commandPool) { this->commandPool = commandPool; } protected: void Init(SamplerManager *samplerManager, OITPipelineManager *pipelineManager, OITBuffers *oitBuffers) @@ -72,7 +66,6 @@ protected: vk::Rect2D viewport; std::array, 2> colorAttachments; std::unique_ptr depthAttachment; - CommandPool *commandPool = nullptr; vk::CommandBuffer currentCommandBuffer; vk::UniqueFramebuffer framebuffer; @@ -136,11 +129,6 @@ public: descriptorSets.clear(); OITDrawer::Term(); } - OITScreenDrawer() = default; - OITScreenDrawer(const OITScreenDrawer& other) = delete; - OITScreenDrawer(OITScreenDrawer&& other) = default; - OITScreenDrawer& operator=(const OITScreenDrawer& other) = delete; - OITScreenDrawer& operator=(OITScreenDrawer&& other) = default; virtual vk::CommandBuffer NewFrame() override; virtual void EndFrame() override @@ -212,11 +200,6 @@ public: OITDrawer::Term(); } - OITTextureDrawer() = default; - OITTextureDrawer(const OITTextureDrawer& other) = delete; - OITTextureDrawer(OITTextureDrawer&& other) = default; - OITTextureDrawer& operator=(const OITTextureDrawer& other) = delete; - OITTextureDrawer& operator=(OITTextureDrawer&& other) = default; virtual void EndFrame() override; protected: diff --git a/core/rend/vulkan/oit_pipeline.cpp b/core/rend/vulkan/oit_pipeline.cpp index 84d8757ce..ed0d7e3bf 100644 --- a/core/rend/vulkan/oit_pipeline.cpp +++ b/core/rend/vulkan/oit_pipeline.cpp @@ -421,16 +421,7 @@ void OITPipelineManager::CreateModVolPipeline(ModVolMode mode) ); // Color flags and blending - vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( - false, // blendEnable - vk::BlendFactor::eZero, // srcColorBlendFactor - vk::BlendFactor::eZero, // dstColorBlendFactor - vk::BlendOp::eAdd, // colorBlendOp - vk::BlendFactor::eZero, // srcAlphaBlendFactor - vk::BlendFactor::eZero, // dstAlphaBlendFactor - vk::BlendOp::eAdd, // alphaBlendOp - vk::ColorComponentFlags() // colorWriteMask - ); + vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState; vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo ( diff --git a/core/rend/vulkan/oit_shaders.cpp b/core/rend/vulkan/oit_shaders.cpp index fe9223740..f8b5790b4 100644 --- a/core/rend/vulkan/oit_shaders.cpp +++ b/core/rend/vulkan/oit_shaders.cpp @@ -560,34 +560,6 @@ void main() } )"; -// FIXME duplicate of non-oit -static const char OITModVolVertexShaderSource[] = R"( -#version 450 - -layout (std140, set = 0, binding = 0) uniform VertexShaderUniforms -{ - mat4 normal_matrix; -} uniformBuffer; - -layout (location = 0) in vec4 in_pos; - -void main() -{ - vec4 vpos = in_pos; - if (vpos.z < 0.0 || vpos.z > 3.4e37) - { - gl_Position = vec4(0.0, 0.0, 1.0, 1.0 / vpos.z); - return; - } - - vpos = uniformBuffer.normal_matrix * vpos; - vpos.w = 1.0 / vpos.z; - vpos.z = vpos.w; - vpos.xy *= vpos.w; - gl_Position = vpos; -} -)"; - static const char OITModifierVolumeShader[] = R"( void main() @@ -864,6 +836,8 @@ void main() } )"; +extern const char ModVolVertexShaderSource[]; + vk::UniqueShaderModule OITShaderManager::compileShader(const VertexShaderParams& params) { char buf[sizeof(OITVertexShaderSource) * 2]; @@ -903,7 +877,7 @@ vk::UniqueShaderModule OITShaderManager::compileClearShader() } vk::UniqueShaderModule OITShaderManager::compileModVolVertexShader() { - return ShaderCompiler::Compile(vk::ShaderStageFlagBits::eVertex, OITModVolVertexShaderSource); + return ShaderCompiler::Compile(vk::ShaderStageFlagBits::eVertex, ModVolVertexShaderSource); } vk::UniqueShaderModule OITShaderManager::compileModVolFragmentShader() { diff --git a/core/rend/vulkan/quad.cpp b/core/rend/vulkan/quad.cpp index 20b70abe7..8efe21a75 100644 --- a/core/rend/vulkan/quad.cpp +++ b/core/rend/vulkan/quad.cpp @@ -115,23 +115,21 @@ void QuadPipeline::CreatePipeline() pipeline = GetContext()->GetDevice().createGraphicsPipelineUnique(GetContext()->GetPipelineCache(), graphicsPipelineCreateInfo); } -void QuadPipeline::Init(ShaderManager *shaderManager) { +void QuadPipeline::Init(ShaderManager *shaderManager, vk::RenderPass renderPass) +{ this->shaderManager = shaderManager; - if (!pipelineLayout) { - vk::DescriptorSetLayoutBinding bindings[] = { { 0, - vk::DescriptorType::eCombinedImageSampler, 1, - vk::ShaderStageFlagBits::eFragment }, // texture - }; - descSetLayout = - GetContext()->GetDevice().createDescriptorSetLayoutUnique( - vk::DescriptorSetLayoutCreateInfo( - vk::DescriptorSetLayoutCreateFlags(), - ARRAY_SIZE(bindings), bindings)); + if (!pipelineLayout) + { + vk::DescriptorSetLayoutBinding bindings[] = { + { 0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment }, // texture + }; + descSetLayout = GetContext()->GetDevice().createDescriptorSetLayoutUnique( + vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), ARRAY_SIZE(bindings), bindings)); pipelineLayout = GetContext()->GetDevice().createPipelineLayoutUnique( - vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, - &descSetLayout.get())); + vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descSetLayout.get())); } - if (!sampler) { + if (!sampler) + { sampler = GetContext()->GetDevice().createSamplerUnique( vk::SamplerCreateInfo(vk::SamplerCreateFlags(), vk::Filter::eLinear, vk::Filter::eLinear, @@ -142,32 +140,29 @@ void QuadPipeline::Init(ShaderManager *shaderManager) { 16.0f, false, vk::CompareOp::eNever, 0.0f, 0.0f, vk::BorderColor::eFloatOpaqueBlack)); } - if (GetContext()->GetRenderPass() != renderPass) { - renderPass = GetContext()->GetRenderPass(); + if (this->renderPass != renderPass) + { + this->renderPass = renderPass; pipeline.reset(); } descriptorSets.resize(GetContext()->GetSwapChainSize()); } -void QuadPipeline::SetTexture(vk::ImageView imageView) { - vk::UniqueDescriptorSet &descriptorSet = - descriptorSets[GetContext()->GetCurrentImageIndex()]; - if (!descriptorSet) { +void QuadPipeline::SetTexture(vk::ImageView imageView) +{ + vk::UniqueDescriptorSet &descriptorSet = descriptorSets[GetContext()->GetCurrentImageIndex()]; + if (!descriptorSet) + { descriptorSet = std::move( GetContext()->GetDevice().allocateDescriptorSetsUnique( - vk::DescriptorSetAllocateInfo( - GetContext()->GetDescriptorPool(), 1, - &descSetLayout.get())).front()); + vk::DescriptorSetAllocateInfo(GetContext()->GetDescriptorPool(), 1, &descSetLayout.get())).front()); } - vk::DescriptorImageInfo imageInfo(*sampler, imageView, - vk::ImageLayout::eShaderReadOnlyOptimal); + vk::DescriptorImageInfo imageInfo(*sampler, imageView, vk::ImageLayout::eShaderReadOnlyOptimal); std::vector writeDescriptorSets; writeDescriptorSets.push_back( - vk::WriteDescriptorSet(*descriptorSet, 0, 0, 1, - vk::DescriptorType::eCombinedImageSampler, &imageInfo, + vk::WriteDescriptorSet(*descriptorSet, 0, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo, nullptr, nullptr)); - GetContext()->GetDevice().updateDescriptorSets(writeDescriptorSets, - nullptr); + GetContext()->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr); } void QuadPipeline::BindDescriptorSets(vk::CommandBuffer cmdBuffer) { diff --git a/core/rend/vulkan/quad.h b/core/rend/vulkan/quad.h index 4c8b7554c..4f74873fa 100644 --- a/core/rend/vulkan/quad.h +++ b/core/rend/vulkan/quad.h @@ -70,7 +70,7 @@ private: class QuadPipeline { public: - void Init(ShaderManager *shaderManager); + void Init(ShaderManager *shaderManager, vk::RenderPass renderPass); vk::Pipeline GetPipeline() { diff --git a/core/rend/vulkan/shaders.cpp b/core/rend/vulkan/shaders.cpp index 7afa4a127..f24f6ac75 100644 --- a/core/rend/vulkan/shaders.cpp +++ b/core/rend/vulkan/shaders.cpp @@ -22,10 +22,7 @@ #include "shaders.h" #include "compiler.h" -static const char VertexShaderSource[] = R"( -#version 400 -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable +static const char VertexShaderSource[] = R"(#version 450 #define pp_Gouraud %d @@ -68,10 +65,7 @@ void main() } )"; -static const char FragmentShaderSource[] = R"( -#version 400 -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable +static const char FragmentShaderSource[] = R"(#version 450 #define cp_AlphaTest %d #define pp_ClipInside %d @@ -238,10 +232,7 @@ void main() } )"; -static const char ModVolVertexShaderSource[] = R"( -#version 400 -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable +extern const char ModVolVertexShaderSource[] = R"(#version 450 layout (std140, set = 0, binding = 0) uniform VertexShaderUniforms { @@ -267,10 +258,7 @@ void main() } )"; -static const char ModVolFragmentShaderSource[] = R"( -#version 400 -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable +static const char ModVolFragmentShaderSource[] = R"(#version 450 layout (location = 0) out vec4 FragColor; @@ -287,10 +275,7 @@ void main() } )"; -static const char QuadVertexShaderSource[] = R"( -#version 400 -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable +static const char QuadVertexShaderSource[] = R"(#version 450 layout (location = 0) in vec3 in_pos; layout (location = 1) in vec2 in_uv; @@ -304,10 +289,7 @@ void main() } )"; -static const char QuadFragmentShaderSource[] = R"( -#version 400 -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable +static const char QuadFragmentShaderSource[] = R"(#version 450 layout (binding = 0) uniform sampler2D tex; layout (location = 0) in vec2 inUV; @@ -319,10 +301,7 @@ void main() } )"; -static const char OSDVertexShaderSource[] = R"( -#version 400 -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable +static const char OSDVertexShaderSource[] = R"(#version 450 layout (location = 0) in vec4 inPos; layout (location = 1) in uvec4 inColor; @@ -338,10 +317,7 @@ void main() } )"; -static const char OSDFragmentShaderSource[] = R"( -#version 400 -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable +static const char OSDFragmentShaderSource[] = R"(#version 450 layout (binding = 0) uniform sampler2D tex; layout (location = 0) in lowp vec4 inColor; diff --git a/core/rend/vulkan/vulkan_context.cpp b/core/rend/vulkan/vulkan_context.cpp index f3ec2539d..6c9bc9064 100644 --- a/core/rend/vulkan/vulkan_context.cpp +++ b/core/rend/vulkan/vulkan_context.cpp @@ -580,7 +580,7 @@ void VulkanContext::CreateSwapChain() renderCompleteSemaphores.push_back(device->createSemaphoreUnique(vk::SemaphoreCreateInfo())); imageAcquiredSemaphores.push_back(device->createSemaphoreUnique(vk::SemaphoreCreateInfo())); } - quadPipeline->Init(shaderManager.get()); + quadPipeline->Init(shaderManager.get(), *renderPass); InitImgui(); diff --git a/core/rend/vulkan/vulkan_renderer.cpp b/core/rend/vulkan/vulkan_renderer.cpp index f88e1947f..0e0b621ec 100644 --- a/core/rend/vulkan/vulkan_renderer.cpp +++ b/core/rend/vulkan/vulkan_renderer.cpp @@ -53,7 +53,7 @@ public: screenDrawer.Init(&samplerManager, &shaderManager); screenDrawer.SetCommandPool(&texCommandPool); - quadPipeline.Init(&shaderManager); + quadPipeline.Init(&shaderManager, screenDrawer.GetRenderPass()); quadBuffer = std::unique_ptr(new QuadBuffer()); #ifdef __ANDROID__ @@ -95,7 +95,7 @@ public: { texCommandPool.Init(); screenDrawer.Init(&samplerManager, &shaderManager); - quadPipeline.Init(&shaderManager); + quadPipeline.Init(&shaderManager, screenDrawer.GetRenderPass()); #ifdef __ANDROID__ osdPipeline.Init(&shaderManager, vjoyTexture->GetImageView(), GetContext()->GetRenderPass()); #endif