Adding MSAA

This commit is contained in:
Dynamitos
2023-12-04 16:36:02 +01:00
parent 34e9304a3c
commit ff8200ab35
9 changed files with 36 additions and 22 deletions
+2 -1
View File
@@ -36,7 +36,6 @@ struct WindowCreateInfo
int32 width; int32 width;
int32 height; int32 height;
const char *title; const char *title;
Gfx::SeSampleCountFlags numSamples;
Gfx::SeFormat preferredFormat = Gfx::SE_FORMAT_MAX_ENUM; Gfx::SeFormat preferredFormat = Gfx::SE_FORMAT_MAX_ENUM;
void *windowHandle; void *windowHandle;
}; };
@@ -44,6 +43,7 @@ struct ViewportCreateInfo
{ {
URect dimensions; URect dimensions;
float fieldOfView = 1.222f; // 70 deg float fieldOfView = 1.222f; // 70 deg
Gfx::SeSampleCountFlags numSamples;
}; };
// doesnt own the data, only proxy it // doesnt own the data, only proxy it
struct DataSource struct DataSource
@@ -65,6 +65,7 @@ struct TextureCreateInfo
uint32 elements = 1; uint32 elements = 1;
uint32 samples = 1; uint32 samples = 1;
Gfx::SeImageUsageFlagBits usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT; Gfx::SeImageUsageFlagBits usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT;
Gfx::SeMemoryPropertyFlags memoryProps = Gfx::SE_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
}; };
struct SamplerCreateInfo struct SamplerCreateInfo
{ {
+11 -5
View File
@@ -184,17 +184,23 @@ void BasePass::endFrame()
void BasePass::publishOutputs() void BasePass::publishOutputs()
{ {
colorAttachment = new Gfx::SwapchainAttachment(viewport->getOwner()); colorBuffer = graphics->createTexture2D(TextureCreateInfo{
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment); .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() void BasePass::createRenderPass()
{ {
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH"); Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD; depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR; Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment, resolveAttachment);
colorAttachment->storeOp = Gfx::SE_ATTACHMENT_STORE_OP_STORE;
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
renderPass = graphics->createRenderPass(std::move(layout), viewport); renderPass = graphics->createRenderPass(std::move(layout), viewport);
oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST"); oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST");
tLightIndexList = resources->requestBuffer("LIGHTCULLING_TLIGHTLIST"); tLightIndexList = resources->requestBuffer("LIGHTCULLING_TLIGHTLIST");
@@ -19,7 +19,9 @@ public:
virtual void createRenderPass() override; virtual void createRenderPass() override;
static void modifyRenderPassMacros(Map<const char*, const char*>& defines); static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
private: private:
Gfx::ORenderTargetAttachment resolveAttachment;
Gfx::ORenderTargetAttachment colorAttachment; Gfx::ORenderTargetAttachment colorAttachment;
Gfx::OTexture2D colorBuffer;
Gfx::PTexture2D depthBuffer; Gfx::PTexture2D depthBuffer;
Gfx::PShaderBuffer oLightIndexList; Gfx::PShaderBuffer oLightIndexList;
Gfx::PShaderBuffer tLightIndexList; Gfx::PShaderBuffer tLightIndexList;
+11 -3
View File
@@ -60,12 +60,11 @@ RenderTargetLayout::RenderTargetLayout(PRenderTargetAttachment depthAttachment)
} }
RenderTargetLayout::RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment) RenderTargetLayout::RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment)
: inputAttachments() : colorAttachments({colorAttachment})
, depthAttachment(depthAttachment) , depthAttachment(depthAttachment)
, width(depthAttachment->getTexture()->getWidth()) , width(depthAttachment->getTexture()->getWidth())
, height(depthAttachment->getTexture()->getHeight()) , height(depthAttachment->getTexture()->getHeight())
{ {
colorAttachments.add(colorAttachment);
} }
RenderTargetLayout::RenderTargetLayout(Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachment) RenderTargetLayout::RenderTargetLayout(Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachment)
: inputAttachments() : inputAttachments()
@@ -82,4 +81,13 @@ RenderTargetLayout::RenderTargetLayout(Array<PRenderTargetAttachment> inputAttac
, width(depthAttachment->getTexture()->getWidth()) , width(depthAttachment->getTexture()->getWidth())
, height(depthAttachment->getTexture()->getHeight()) , height(depthAttachment->getTexture()->getHeight())
{ {
} }
RenderTargetLayout::RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment, PRenderTargetAttachment resolveAttachment)
: colorAttachments({ colorAttachment })
, depthAttachment(depthAttachment)
, resolveAttachments({ resolveAttachment })
, width(depthAttachment->getTexture()->getWidth())
, height(depthAttachment->getTexture()->getHeight())
{
}
+6 -5
View File
@@ -36,10 +36,10 @@ public:
{ {
return texture->getHeight(); return texture->getHeight();
} }
inline SeAttachmentLoadOp getLoadOp() const { return loadOp; } constexpr SeAttachmentLoadOp getLoadOp() const { return loadOp; }
inline SeAttachmentStoreOp getStoreOp() const { return storeOp; } constexpr SeAttachmentStoreOp getStoreOp() const { return storeOp; }
inline SeAttachmentLoadOp getStencilLoadOp() const { return stencilLoadOp; } constexpr SeAttachmentLoadOp getStencilLoadOp() const { return stencilLoadOp; }
inline SeAttachmentStoreOp getStencilStoreOp() const { return stencilStoreOp; } constexpr SeAttachmentStoreOp getStencilStoreOp() const { return stencilStoreOp; }
SeClearValue clear; SeClearValue clear;
SeColorComponentFlags componentFlags; SeColorComponentFlags componentFlags;
SeAttachmentLoadOp loadOp; SeAttachmentLoadOp loadOp;
@@ -70,7 +70,7 @@ public:
} }
virtual SeSampleCountFlags getNumSamples() const override virtual SeSampleCountFlags getNumSamples() const override
{ {
return owner->getNumSamples(); return Gfx::SE_SAMPLE_COUNT_1_BIT;
} }
virtual uint32 getWidth() const virtual uint32 getWidth() const
{ {
@@ -93,6 +93,7 @@ public:
RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment); RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment);
RenderTargetLayout(Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachmet); RenderTargetLayout(Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachmet);
RenderTargetLayout(Array<PRenderTargetAttachment> inputAttachments, Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachment); RenderTargetLayout(Array<PRenderTargetAttachment> inputAttachments, Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachment);
RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment, PRenderTargetAttachment resolveAttachment);
Array<PRenderTargetAttachment> inputAttachments; Array<PRenderTargetAttachment> inputAttachments;
Array<PRenderTargetAttachment> colorAttachments; Array<PRenderTargetAttachment> colorAttachments;
Array<PRenderTargetAttachment> resolveAttachments; Array<PRenderTargetAttachment> resolveAttachments;
+1 -1
View File
@@ -112,7 +112,7 @@ TextureBase::TextureBase(PGraphics graphics, VkImageViewType viewType,
}; };
vkGetImageMemoryRequirements2(graphics->getDevice(), &reqInfo, &requirements); 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()); vkBindImageMemory(graphics->getDevice(), image, allocation->getHandle(), allocation->getOffset());
} }
-2
View File
@@ -64,7 +64,6 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
, preferences(createInfo) , preferences(createInfo)
, instance(graphics->getInstance()) , instance(graphics->getInstance())
, swapchain(VK_NULL_HANDLE) , swapchain(VK_NULL_HANDLE)
, numSamples(createInfo.numSamples)
{ {
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow *handle = glfwCreateWindow(createInfo.width, createInfo.height, createInfo.title, nullptr, nullptr); GLFWwindow *handle = glfwCreateWindow(createInfo.width, createInfo.height, createInfo.title, nullptr, nullptr);
@@ -88,7 +87,6 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
chooseSwapExtent(); chooseSwapExtent();
framebufferWidth = extent.width; framebufferWidth = extent.width;
framebufferHeight = extent.height; framebufferHeight = extent.height;
sampleFlags = createInfo.numSamples;
createSwapChain(); createSwapChain();
} }
+1
View File
@@ -18,6 +18,7 @@ Viewport::Viewport(PWindow owner, const ViewportCreateInfo& viewportInfo)
, offsetX(viewportInfo.dimensions.offset.x) , offsetX(viewportInfo.dimensions.offset.x)
, offsetY(viewportInfo.dimensions.offset.y) , offsetY(viewportInfo.dimensions.offset.y)
, fieldOfView(viewportInfo.fieldOfView) , fieldOfView(viewportInfo.fieldOfView)
, samples(viewportInfo.numSamples)
, owner(owner) , owner(owner)
{ {
} }
+2 -5
View File
@@ -26,10 +26,6 @@ public:
{ {
return framebufferFormat; return framebufferFormat;
} }
constexpr SeSampleCountFlags getNumSamples() const
{
return sampleFlags;
}
constexpr uint32 getFramebufferWidth() const constexpr uint32 getFramebufferWidth() const
{ {
return framebufferWidth; return framebufferWidth;
@@ -41,7 +37,6 @@ public:
protected: protected:
SeFormat framebufferFormat; SeFormat framebufferFormat;
SeSampleCountFlags sampleFlags;
uint32 framebufferWidth; uint32 framebufferWidth;
uint32 framebufferHeight; uint32 framebufferHeight;
}; };
@@ -59,6 +54,7 @@ public:
constexpr uint32 getHeight() const { return sizeY; } constexpr uint32 getHeight() const { return sizeY; }
constexpr uint32 getOffsetX() const { return offsetX; } constexpr uint32 getOffsetX() const { return offsetX; }
constexpr uint32 getOffsetY() const { return offsetY; } constexpr uint32 getOffsetY() const { return offsetY; }
constexpr Gfx::SeSampleCountFlags getSamples() const { return samples; }
Matrix4 getProjectionMatrix() const; Matrix4 getProjectionMatrix() const;
protected: protected:
uint32 sizeX; uint32 sizeX;
@@ -66,6 +62,7 @@ protected:
uint32 offsetX; uint32 offsetX;
uint32 offsetY; uint32 offsetY;
float fieldOfView; float fieldOfView;
Gfx::SeSampleCountFlags samples;
PWindow owner; PWindow owner;
}; };
DEFINE_REF(Viewport) DEFINE_REF(Viewport)