diff --git a/src/Engine/Graphics/Initializer.h b/src/Engine/Graphics/Initializer.h index 22e0de4..29f69f5 100644 --- a/src/Engine/Graphics/Initializer.h +++ b/src/Engine/Graphics/Initializer.h @@ -36,7 +36,6 @@ struct WindowCreateInfo int32 width; int32 height; const char *title; - Gfx::SeSampleCountFlags numSamples; Gfx::SeFormat preferredFormat = Gfx::SE_FORMAT_MAX_ENUM; void *windowHandle; }; @@ -44,6 +43,7 @@ struct ViewportCreateInfo { URect dimensions; float fieldOfView = 1.222f; // 70 deg + Gfx::SeSampleCountFlags numSamples; }; // doesnt own the data, only proxy it struct DataSource @@ -65,6 +65,7 @@ struct TextureCreateInfo uint32 elements = 1; uint32 samples = 1; Gfx::SeImageUsageFlagBits usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT; + Gfx::SeMemoryPropertyFlags memoryProps = Gfx::SE_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; }; struct SamplerCreateInfo { diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index 5c6e553..5482130 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -184,17 +184,23 @@ void BasePass::endFrame() void BasePass::publishOutputs() { - colorAttachment = new Gfx::SwapchainAttachment(viewport->getOwner()); - resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment); + colorBuffer = graphics->createTexture2D(TextureCreateInfo{ + .width = viewport->getWidth(), + .height = viewport->getHeight(), + .samples = viewport->getSamples(), + .usage = Gfx::SE_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, + .memoryProps = Gfx::SE_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | Gfx::SE_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, + }); + colorAttachment = new Gfx::RenderTargetAttachment(colorBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_DONT_CARE); + resolveAttachment = new Gfx::SwapchainAttachment(viewport->getOwner(), Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE); + resources->registerRenderPassOutput("BASEPASS_COLOR", resolveAttachment); } void BasePass::createRenderPass() { Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH"); depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD; - colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR; - colorAttachment->storeOp = Gfx::SE_ATTACHMENT_STORE_OP_STORE; - Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment); + Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment, resolveAttachment); renderPass = graphics->createRenderPass(std::move(layout), viewport); oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST"); tLightIndexList = resources->requestBuffer("LIGHTCULLING_TLIGHTLIST"); diff --git a/src/Engine/Graphics/RenderPass/BasePass.h b/src/Engine/Graphics/RenderPass/BasePass.h index 9d8b589..741c887 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.h +++ b/src/Engine/Graphics/RenderPass/BasePass.h @@ -19,7 +19,9 @@ public: virtual void createRenderPass() override; static void modifyRenderPassMacros(Map& defines); private: + Gfx::ORenderTargetAttachment resolveAttachment; Gfx::ORenderTargetAttachment colorAttachment; + Gfx::OTexture2D colorBuffer; Gfx::PTexture2D depthBuffer; Gfx::PShaderBuffer oLightIndexList; Gfx::PShaderBuffer tLightIndexList; diff --git a/src/Engine/Graphics/RenderTarget.cpp b/src/Engine/Graphics/RenderTarget.cpp index 5a1e121..d165d15 100644 --- a/src/Engine/Graphics/RenderTarget.cpp +++ b/src/Engine/Graphics/RenderTarget.cpp @@ -60,12 +60,11 @@ RenderTargetLayout::RenderTargetLayout(PRenderTargetAttachment depthAttachment) } RenderTargetLayout::RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment) - : inputAttachments() + : colorAttachments({colorAttachment}) , depthAttachment(depthAttachment) , width(depthAttachment->getTexture()->getWidth()) , height(depthAttachment->getTexture()->getHeight()) { - colorAttachments.add(colorAttachment); } RenderTargetLayout::RenderTargetLayout(Array colorAttachments, PRenderTargetAttachment depthAttachment) : inputAttachments() @@ -82,4 +81,13 @@ RenderTargetLayout::RenderTargetLayout(Array inputAttac , width(depthAttachment->getTexture()->getWidth()) , height(depthAttachment->getTexture()->getHeight()) { -} \ No newline at end of file +} + +RenderTargetLayout::RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment, PRenderTargetAttachment resolveAttachment) + : colorAttachments({ colorAttachment }) + , depthAttachment(depthAttachment) + , resolveAttachments({ resolveAttachment }) + , width(depthAttachment->getTexture()->getWidth()) + , height(depthAttachment->getTexture()->getHeight()) +{ +} diff --git a/src/Engine/Graphics/RenderTarget.h b/src/Engine/Graphics/RenderTarget.h index e74365d..f0b73dd 100644 --- a/src/Engine/Graphics/RenderTarget.h +++ b/src/Engine/Graphics/RenderTarget.h @@ -36,10 +36,10 @@ public: { return texture->getHeight(); } - inline SeAttachmentLoadOp getLoadOp() const { return loadOp; } - inline SeAttachmentStoreOp getStoreOp() const { return storeOp; } - inline SeAttachmentLoadOp getStencilLoadOp() const { return stencilLoadOp; } - inline SeAttachmentStoreOp getStencilStoreOp() const { return stencilStoreOp; } + constexpr SeAttachmentLoadOp getLoadOp() const { return loadOp; } + constexpr SeAttachmentStoreOp getStoreOp() const { return storeOp; } + constexpr SeAttachmentLoadOp getStencilLoadOp() const { return stencilLoadOp; } + constexpr SeAttachmentStoreOp getStencilStoreOp() const { return stencilStoreOp; } SeClearValue clear; SeColorComponentFlags componentFlags; SeAttachmentLoadOp loadOp; @@ -70,7 +70,7 @@ public: } virtual SeSampleCountFlags getNumSamples() const override { - return owner->getNumSamples(); + return Gfx::SE_SAMPLE_COUNT_1_BIT; } virtual uint32 getWidth() const { @@ -93,6 +93,7 @@ public: RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment); RenderTargetLayout(Array colorAttachments, PRenderTargetAttachment depthAttachmet); RenderTargetLayout(Array inputAttachments, Array colorAttachments, PRenderTargetAttachment depthAttachment); + RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment, PRenderTargetAttachment resolveAttachment); Array inputAttachments; Array colorAttachments; Array resolveAttachments; diff --git a/src/Engine/Graphics/Vulkan/Texture.cpp b/src/Engine/Graphics/Vulkan/Texture.cpp index 4e07859..ca44bf4 100644 --- a/src/Engine/Graphics/Vulkan/Texture.cpp +++ b/src/Engine/Graphics/Vulkan/Texture.cpp @@ -112,7 +112,7 @@ TextureBase::TextureBase(PGraphics graphics, VkImageViewType viewType, }; vkGetImageMemoryRequirements2(graphics->getDevice(), &reqInfo, &requirements); - allocation = pool->allocate(requirements, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, image); + allocation = pool->allocate(requirements, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, image); vkBindImageMemory(graphics->getDevice(), image, allocation->getHandle(), allocation->getOffset()); } diff --git a/src/Engine/Graphics/Vulkan/Window.cpp b/src/Engine/Graphics/Vulkan/Window.cpp index 3003e26..735de61 100644 --- a/src/Engine/Graphics/Vulkan/Window.cpp +++ b/src/Engine/Graphics/Vulkan/Window.cpp @@ -64,7 +64,6 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo) , preferences(createInfo) , instance(graphics->getInstance()) , swapchain(VK_NULL_HANDLE) - , numSamples(createInfo.numSamples) { glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); GLFWwindow *handle = glfwCreateWindow(createInfo.width, createInfo.height, createInfo.title, nullptr, nullptr); @@ -88,7 +87,6 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo) chooseSwapExtent(); framebufferWidth = extent.width; framebufferHeight = extent.height; - sampleFlags = createInfo.numSamples; createSwapChain(); } diff --git a/src/Engine/Graphics/Window.cpp b/src/Engine/Graphics/Window.cpp index 4148c4f..4759608 100644 --- a/src/Engine/Graphics/Window.cpp +++ b/src/Engine/Graphics/Window.cpp @@ -18,6 +18,7 @@ Viewport::Viewport(PWindow owner, const ViewportCreateInfo& viewportInfo) , offsetX(viewportInfo.dimensions.offset.x) , offsetY(viewportInfo.dimensions.offset.y) , fieldOfView(viewportInfo.fieldOfView) + , samples(viewportInfo.numSamples) , owner(owner) { } diff --git a/src/Engine/Graphics/Window.h b/src/Engine/Graphics/Window.h index b5272d7..276d6c3 100644 --- a/src/Engine/Graphics/Window.h +++ b/src/Engine/Graphics/Window.h @@ -26,10 +26,6 @@ public: { return framebufferFormat; } - constexpr SeSampleCountFlags getNumSamples() const - { - return sampleFlags; - } constexpr uint32 getFramebufferWidth() const { return framebufferWidth; @@ -41,7 +37,6 @@ public: protected: SeFormat framebufferFormat; - SeSampleCountFlags sampleFlags; uint32 framebufferWidth; uint32 framebufferHeight; }; @@ -59,6 +54,7 @@ public: constexpr uint32 getHeight() const { return sizeY; } constexpr uint32 getOffsetX() const { return offsetX; } constexpr uint32 getOffsetY() const { return offsetY; } + constexpr Gfx::SeSampleCountFlags getSamples() const { return samples; } Matrix4 getProjectionMatrix() const; protected: uint32 sizeX; @@ -66,6 +62,7 @@ protected: uint32 offsetX; uint32 offsetY; float fieldOfView; + Gfx::SeSampleCountFlags samples; PWindow owner; }; DEFINE_REF(Viewport)