Adding MSAA
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -19,7 +19,9 @@ public:
|
||||
virtual void createRenderPass() override;
|
||||
static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
|
||||
private:
|
||||
Gfx::ORenderTargetAttachment resolveAttachment;
|
||||
Gfx::ORenderTargetAttachment colorAttachment;
|
||||
Gfx::OTexture2D colorBuffer;
|
||||
Gfx::PTexture2D depthBuffer;
|
||||
Gfx::PShaderBuffer oLightIndexList;
|
||||
Gfx::PShaderBuffer tLightIndexList;
|
||||
|
||||
@@ -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<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachment)
|
||||
: inputAttachments()
|
||||
@@ -83,3 +82,12 @@ RenderTargetLayout::RenderTargetLayout(Array<PRenderTargetAttachment> inputAttac
|
||||
, 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())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachmet);
|
||||
RenderTargetLayout(Array<PRenderTargetAttachment> inputAttachments, Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachment);
|
||||
RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment, PRenderTargetAttachment resolveAttachment);
|
||||
Array<PRenderTargetAttachment> inputAttachments;
|
||||
Array<PRenderTargetAttachment> colorAttachments;
|
||||
Array<PRenderTargetAttachment> resolveAttachments;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user