Initial environment loading (not working)
This commit is contained in:
@@ -68,9 +68,7 @@ class DescriptorSet {
|
||||
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer indexBuffer) = 0;
|
||||
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer indexBuffer) = 0;
|
||||
virtual void updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) = 0;
|
||||
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture2D texture) = 0;
|
||||
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture3D texture) = 0;
|
||||
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTextureCube texture) = 0;
|
||||
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture texture) = 0;
|
||||
virtual void updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) = 0;
|
||||
bool operator<(PDescriptorSet other);
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ class Graphics {
|
||||
virtual OWindow createWindow(const WindowCreateInfo& createInfo) = 0;
|
||||
virtual OViewport createViewport(PWindow owner, const ViewportCreateInfo& createInfo) = 0;
|
||||
|
||||
virtual ORenderPass createRenderPass(RenderTargetLayout layout, Array<SubPassDependency> dependencies, PViewport renderArea,
|
||||
std::string name = "") = 0;
|
||||
virtual ORenderPass createRenderPass(RenderTargetLayout layout, Array<SubPassDependency> dependencies, URect renderArea,
|
||||
std::string name = "", Array<uint32> viewMasks = {}, Array<uint32> correlationMasks = {}) = 0;
|
||||
virtual void beginRenderPass(PRenderPass renderPass) = 0;
|
||||
virtual void endRenderPass() = 0;
|
||||
virtual void waitDeviceIdle() = 0;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "RayTracing.h"
|
||||
#include "RayTracing.h"
|
||||
|
||||
using namespace Seele::Gfx;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "Resources.h"
|
||||
#include "Graphics/Descriptor.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace Gfx {
|
||||
|
||||
@@ -407,7 +407,7 @@ void BasePass::publishOutputs() {
|
||||
});
|
||||
|
||||
depthAttachment =
|
||||
Gfx::RenderTargetAttachment(basePassDepth, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
||||
Gfx::RenderTargetAttachment(Gfx::PTexture2D(basePassDepth), Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
||||
Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
|
||||
|
||||
msDepthAttachment =
|
||||
@@ -472,7 +472,7 @@ void BasePass::createRenderPass() {
|
||||
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
||||
},
|
||||
};
|
||||
renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport, "BasePass");
|
||||
renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport->getRenderArea(), "BasePass");
|
||||
oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST");
|
||||
tLightIndexList = resources->requestBuffer("LIGHTCULLING_TLIGHTLIST");
|
||||
oLightGrid = resources->requestTexture("LIGHTCULLING_OLIGHTGRID");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "CachedDepthPass.h"
|
||||
#include "Graphics/Shader.h"
|
||||
#include "Graphics/Pipeline.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -202,5 +203,5 @@ void CachedDepthPass::createRenderPass() {
|
||||
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
||||
},
|
||||
};
|
||||
renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport, "CachedDepthPass");
|
||||
renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport->getRenderArea(), "CachedDepthPass");
|
||||
}
|
||||
|
||||
@@ -306,5 +306,5 @@ void DepthCullingPass::createRenderPass() {
|
||||
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
||||
},
|
||||
};
|
||||
renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport, "DepthCullingPass");
|
||||
renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport->getRenderArea(), "DepthCullingPass");
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Component/Camera.h"
|
||||
#include "Graphics/Command.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/Pipeline.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "RenderGraph.h"
|
||||
#include "Scene/Scene.h"
|
||||
@@ -48,8 +49,8 @@ void LightCullingPass::render() {
|
||||
cullingDescriptorSet->updateBuffer(TLIGHTINDEXCOUNTER_NAME, 0, tLightIndexCounter);
|
||||
cullingDescriptorSet->updateBuffer(OLIGHTINDEXLIST_NAME, 0, oLightIndexList);
|
||||
cullingDescriptorSet->updateBuffer(TLIGHTINDEXLIST_NAME, 0, tLightIndexList);
|
||||
cullingDescriptorSet->updateTexture(OLIGHTGRID_NAME, 0, oLightGrid);
|
||||
cullingDescriptorSet->updateTexture(TLIGHTGRID_NAME, 0, tLightGrid);
|
||||
cullingDescriptorSet->updateTexture(OLIGHTGRID_NAME, 0, Gfx::PTexture2D(oLightGrid));
|
||||
cullingDescriptorSet->updateTexture(TLIGHTGRID_NAME, 0, Gfx::PTexture2D(tLightGrid));
|
||||
cullingDescriptorSet->writeChanges();
|
||||
Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("CullingCommand");
|
||||
if (getGlobals().useLightCulling) {
|
||||
|
||||
@@ -151,8 +151,8 @@ void RayTracingPass::render() {
|
||||
});
|
||||
Gfx::PDescriptorSet desc = paramsLayout->allocateDescriptorSet();
|
||||
desc->updateAccelerationStructure(TLAS_NAME, 0, tlas);
|
||||
desc->updateTexture(ACCUMULATOR_NAME, 0, radianceAccumulator);
|
||||
desc->updateTexture(TEXTURE_NAME, 0, texture);
|
||||
desc->updateTexture(ACCUMULATOR_NAME, 0, Gfx::PTexture2D(radianceAccumulator));
|
||||
desc->updateTexture(TEXTURE_NAME, 0, Gfx::PTexture2D(texture));
|
||||
desc->updateBuffer(INDEXBUFFER_NAME, 0, StaticMeshVertexData::getInstance()->getIndexBuffer());
|
||||
desc->updateTexture(SKYBOX_NAME, 0, skyBox);
|
||||
desc->updateSampler(SKYSAMPLER_NAME, 0, skyBoxSampler);
|
||||
|
||||
@@ -216,7 +216,7 @@ void ToneMappingPass::createRenderPass() {
|
||||
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
},
|
||||
};
|
||||
renderPass = graphics->createRenderPass(targetLayout, dependency, viewport, "ToneMappingPass");
|
||||
renderPass = graphics->createRenderPass(targetLayout, dependency, viewport->getRenderArea(), "ToneMappingPass");
|
||||
pipeline = graphics->createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo{
|
||||
.vertexShader = vert,
|
||||
.fragmentShader = frag,
|
||||
|
||||
@@ -170,7 +170,7 @@ void UIPass::createRenderPass() {
|
||||
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
|
||||
},
|
||||
};
|
||||
renderPass = graphics->createRenderPass(std::move(layout), dependency, viewport, "TextPass");
|
||||
renderPass = graphics->createRenderPass(std::move(layout), dependency, viewport->getRenderArea(), "TextPass");
|
||||
|
||||
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
||||
.name = "TextVertex",
|
||||
|
||||
@@ -9,6 +9,12 @@ RenderTargetAttachment::RenderTargetAttachment(PTexture2D texture, SeImageLayout
|
||||
: clear(), componentFlags(0), texture(texture), initialLayout(initialLayout), finalLayout(finalLayout), loadOp(loadOp),
|
||||
storeOp(storeOp), stencilLoadOp(stencilLoadOp), stencilStoreOp(stencilStoreOp) {}
|
||||
|
||||
RenderTargetAttachment::RenderTargetAttachment(PTextureCube texture, SeImageLayout initialLayout, SeImageLayout finalLayout,
|
||||
SeAttachmentLoadOp loadOp, SeAttachmentStoreOp storeOp, SeAttachmentLoadOp stencilLoadOp,
|
||||
SeAttachmentStoreOp stencilStoreOp)
|
||||
: clear(), componentFlags(0), texture(texture), initialLayout(initialLayout), finalLayout(finalLayout), loadOp(loadOp),
|
||||
storeOp(storeOp), stencilLoadOp(stencilLoadOp), stencilStoreOp(stencilStoreOp) {}
|
||||
|
||||
RenderTargetAttachment::RenderTargetAttachment(PViewport viewport, SeImageLayout initialLayout, SeImageLayout finalLayout,
|
||||
SeAttachmentLoadOp loadOp, SeAttachmentStoreOp storeOp, SeAttachmentLoadOp stencilLoadOp,
|
||||
SeAttachmentStoreOp stencilStoreOp)
|
||||
|
||||
@@ -14,16 +14,21 @@ class RenderTargetAttachment {
|
||||
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE,
|
||||
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE,
|
||||
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE);
|
||||
|
||||
RenderTargetAttachment(PTextureCube texture, SeImageLayout initialLayout, SeImageLayout finalLayout,
|
||||
SeAttachmentLoadOp loadOp = SE_ATTACHMENT_LOAD_OP_LOAD,
|
||||
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE,
|
||||
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE,
|
||||
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE);
|
||||
RenderTargetAttachment(PViewport viewport, SeImageLayout initialLayout, SeImageLayout finalLayout,
|
||||
SeAttachmentLoadOp loadOp = SE_ATTACHMENT_LOAD_OP_LOAD,
|
||||
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE,
|
||||
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE,
|
||||
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE);
|
||||
~RenderTargetAttachment();
|
||||
PTexture2D getTexture() const {
|
||||
void setTexture(PTexture _texture) { texture = _texture; }
|
||||
PTexture getTexture() const {
|
||||
if (viewport != nullptr) {
|
||||
return viewport->getOwner()->getBackBuffer();
|
||||
return PTexture(viewport->getOwner()->getBackBuffer());
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
@@ -68,7 +73,7 @@ class RenderTargetAttachment {
|
||||
SeColorComponentFlags componentFlags = 0;
|
||||
|
||||
protected:
|
||||
PTexture2D texture = nullptr;
|
||||
PTexture texture = nullptr;
|
||||
PViewport viewport = nullptr;
|
||||
SeImageLayout initialLayout = SE_IMAGE_LAYOUT_UNDEFINED;
|
||||
SeImageLayout finalLayout = SE_IMAGE_LAYOUT_UNDEFINED;
|
||||
@@ -103,6 +108,7 @@ class RenderPass {
|
||||
RenderPass(RenderPass&&) = default;
|
||||
RenderPass& operator=(RenderPass&&) = default;
|
||||
const RenderTargetLayout& getLayout() const { return layout; }
|
||||
void updateColorAttachment(uint32 index, Gfx::PTextureCube attachment) { layout.colorAttachments[index].setTexture(attachment); }
|
||||
|
||||
protected:
|
||||
RenderTargetLayout layout;
|
||||
|
||||
@@ -312,63 +312,7 @@ void DescriptorSet::updateSampler(const std::string& mappingName, uint32 index,
|
||||
boundResources[binding][index] = vulkanSampler->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateTexture(const std::string& mappingName, uint32 index, Gfx::PTexture2D texture) {
|
||||
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
|
||||
const auto& map = owner->getLayout()->mappings[mappingName];
|
||||
uint32 binding = map.binding;
|
||||
if (boundResources[binding][index] == vulkanTexture->getHandle()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// It is assumed that the image is in the correct layout
|
||||
imageInfos.add(VkDescriptorImageInfo{
|
||||
.sampler = VK_NULL_HANDLE,
|
||||
.imageView = vulkanTexture->getView(),
|
||||
.imageLayout = cast(vulkanTexture->getLayout()),
|
||||
});
|
||||
writeDescriptors.add(VkWriteDescriptorSet{
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
.pNext = nullptr,
|
||||
.dstSet = setHandle,
|
||||
.dstBinding = binding,
|
||||
.dstArrayElement = index,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = map.type,
|
||||
.pImageInfo = &imageInfos.back(),
|
||||
});
|
||||
|
||||
boundResources[binding][index] = vulkanTexture->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateTexture(const std::string& mappingName, uint32 index, Gfx::PTexture3D texture) {
|
||||
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
|
||||
const auto& map = owner->getLayout()->mappings[mappingName];
|
||||
uint32 binding = map.binding;
|
||||
if (boundResources[binding][index] == vulkanTexture->getHandle()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// It is assumed that the image is in the correct layout
|
||||
imageInfos.add(VkDescriptorImageInfo{
|
||||
.sampler = VK_NULL_HANDLE,
|
||||
.imageView = vulkanTexture->getView(),
|
||||
.imageLayout = cast(vulkanTexture->getLayout()),
|
||||
});
|
||||
writeDescriptors.add(VkWriteDescriptorSet{
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
.pNext = nullptr,
|
||||
.dstSet = setHandle,
|
||||
.dstBinding = binding,
|
||||
.dstArrayElement = index,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = map.type,
|
||||
.pImageInfo = &imageInfos.back(),
|
||||
});
|
||||
|
||||
boundResources[binding][index] = vulkanTexture->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateTexture(const std::string& mappingName, uint32 index, Gfx::PTextureCube texture) {
|
||||
void DescriptorSet::updateTexture(const std::string& mappingName, uint32 index, Gfx::PTexture texture) {
|
||||
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
|
||||
const auto& map = owner->getLayout()->mappings[mappingName];
|
||||
uint32 binding = map.binding;
|
||||
|
||||
@@ -64,9 +64,7 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
|
||||
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer indexBuffer) override;
|
||||
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer indexBuffer) override;
|
||||
virtual void updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) override;
|
||||
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture2D texture) override;
|
||||
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture3D texture) override;
|
||||
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTextureCube texture) override;
|
||||
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture texture) override;
|
||||
virtual void updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) override;
|
||||
|
||||
constexpr VkDescriptorSet getHandle() const { return setHandle; }
|
||||
|
||||
@@ -17,35 +17,35 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::Render
|
||||
uint32 width = 0;
|
||||
uint32 height = 0;
|
||||
for (auto inputAttachment : layout.inputAttachments) {
|
||||
PTexture2D vkInputAttachment = inputAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase vkInputAttachment = inputAttachment.getTexture().cast<TextureBase>();
|
||||
attachments.add(vkInputAttachment->getView());
|
||||
description.inputAttachments[description.numInputAttachments++] = vkInputAttachment->getView();
|
||||
width = std::max(width, vkInputAttachment->getWidth());
|
||||
height = std::max(height, vkInputAttachment->getHeight());
|
||||
}
|
||||
for (auto colorAttachment : layout.colorAttachments) {
|
||||
PTexture2D vkColorAttachment = colorAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase vkColorAttachment = colorAttachment.getTexture().cast<TextureBase>();
|
||||
attachments.add(vkColorAttachment->getView());
|
||||
description.colorAttachments[description.numColorAttachments++] = vkColorAttachment->getView();
|
||||
width = std::max(width, vkColorAttachment->getWidth());
|
||||
height = std::max(height, vkColorAttachment->getHeight());
|
||||
}
|
||||
for (auto resolveAttachment : layout.resolveAttachments) {
|
||||
PTexture2D vkResolveAttachment = resolveAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase vkResolveAttachment = resolveAttachment.getTexture().cast<TextureBase>();
|
||||
attachments.add(vkResolveAttachment->getView());
|
||||
description.resolveAttachments[description.numResolveAttachments++] = vkResolveAttachment->getView();
|
||||
width = std::max(width, vkResolveAttachment->getWidth());
|
||||
height = std::max(height, vkResolveAttachment->getHeight());
|
||||
}
|
||||
if (layout.depthAttachment.getTexture() != nullptr) {
|
||||
PTexture2D vkDepthAttachment = layout.depthAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase vkDepthAttachment = layout.depthAttachment.getTexture().cast<TextureBase>();
|
||||
attachments.add(vkDepthAttachment->getView());
|
||||
description.depthAttachment = vkDepthAttachment->getView();
|
||||
width = std::max(width, vkDepthAttachment->getWidth());
|
||||
height = std::max(height, vkDepthAttachment->getHeight());
|
||||
}
|
||||
if (layout.depthResolveAttachment.getTexture() != nullptr) {
|
||||
PTexture2D vkDepthAttachment = layout.depthResolveAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase vkDepthAttachment = layout.depthResolveAttachment.getTexture().cast<TextureBase>();
|
||||
attachments.add(vkDepthAttachment->getView());
|
||||
description.depthResolveAttachment = vkDepthAttachment->getView();
|
||||
width = std::max(width, vkDepthAttachment->getWidth());
|
||||
|
||||
@@ -172,8 +172,9 @@ Gfx::OViewport Graphics::createViewport(Gfx::PWindow owner, const ViewportCreate
|
||||
}
|
||||
|
||||
Gfx::ORenderPass Graphics::createRenderPass(Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies,
|
||||
Gfx::PViewport renderArea, std::string name) {
|
||||
return new RenderPass(this, std::move(layout), std::move(dependencies), renderArea, name);
|
||||
URect renderArea, std::string name, Array<uint32> viewMasks,
|
||||
Array<uint32> correlationMasks) {
|
||||
return new RenderPass(this, std::move(layout), std::move(dependencies), renderArea, name, std::move(viewMasks), std::move(correlationMasks));
|
||||
}
|
||||
void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) {
|
||||
PRenderPass rp = renderPass.cast<RenderPass>();
|
||||
@@ -824,6 +825,7 @@ void Graphics::pickPhysicalDevice() {
|
||||
.pNext = &features12,
|
||||
.storageBuffer16BitAccess = true,
|
||||
.uniformAndStorageBuffer16BitAccess = true,
|
||||
.multiview = true,
|
||||
};
|
||||
features = {
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
|
||||
@@ -950,6 +952,7 @@ void Graphics::createDevice(GraphicsInitializer initializer) {
|
||||
initializer.deviceExtensions.add(VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME);
|
||||
initializer.deviceExtensions.add(VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME);
|
||||
}
|
||||
initializer.deviceExtensions.add(VK_KHR_MULTIVIEW_EXTENSION_NAME);
|
||||
#ifdef __APPLE__
|
||||
initializer.deviceExtensions.add("VK_KHR_portability_subset");
|
||||
#endif
|
||||
|
||||
@@ -35,7 +35,8 @@ class Graphics : public Gfx::Graphics {
|
||||
virtual Gfx::OViewport createViewport(Gfx::PWindow owner, const ViewportCreateInfo& createInfo) override;
|
||||
|
||||
virtual Gfx::ORenderPass createRenderPass(Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies,
|
||||
Gfx::PViewport renderArea, std::string name) override;
|
||||
URect renderArea, std::string name, Array<uint32> viewMasks,
|
||||
Array<uint32> correlationMasks) override;
|
||||
virtual void beginRenderPass(Gfx::PRenderPass renderPass) override;
|
||||
virtual void endRenderPass() override;
|
||||
virtual void waitDeviceIdle() override;
|
||||
|
||||
@@ -6,17 +6,16 @@
|
||||
#include "Resources.h"
|
||||
#include "Texture.h"
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Array<Gfx::SubPassDependency> _dependencies,
|
||||
Gfx::PViewport viewport, std::string name)
|
||||
URect viewport, std::string name, Array<uint32> viewMasks, Array<uint32> correlationMasks)
|
||||
: Gfx::RenderPass(std::move(_layout), std::move(_dependencies)), graphics(graphics) {
|
||||
renderArea.extent.width = viewport->getWidth();
|
||||
renderArea.extent.height = viewport->getHeight();
|
||||
renderArea.offset.x = viewport->getOffsetX();
|
||||
renderArea.offset.y = viewport->getOffsetY();
|
||||
renderArea.extent.width = viewport.size.x;
|
||||
renderArea.extent.height = viewport.size.y;
|
||||
renderArea.offset.x = viewport.offset.x;
|
||||
renderArea.offset.y = viewport.offset.y;
|
||||
subpassContents = VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS;
|
||||
Array<VkAttachmentDescription2> attachments;
|
||||
Array<VkAttachmentReference2> inputRefs;
|
||||
@@ -198,7 +197,18 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Arra
|
||||
.dependencyCount = (uint32)dep.size(),
|
||||
.pDependencies = dep.data(),
|
||||
};
|
||||
|
||||
VkRenderPassMultiviewCreateInfo multiViewInfo;
|
||||
if (!viewMasks.empty()) {
|
||||
multiViewInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.subpassCount = 1,
|
||||
.pViewMasks = viewMasks.data(),
|
||||
.correlationMaskCount = (uint32)correlationMasks.size(),
|
||||
.pCorrelationMasks = correlationMasks.data(),
|
||||
};
|
||||
info.pNext = &multiViewInfo;
|
||||
}
|
||||
VK_CHECK(vkCreateRenderPass2(graphics->getDevice(), &info, nullptr, &renderPass));
|
||||
VkDebugUtilsObjectNameInfoEXT nameInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
|
||||
@@ -220,23 +230,23 @@ uint32 RenderPass::getFramebufferHash() {
|
||||
FramebufferDescription description;
|
||||
std::memset(&description, 0, sizeof(FramebufferDescription));
|
||||
for (auto& inputAttachment : layout.inputAttachments) {
|
||||
PTexture2D tex = inputAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase tex = inputAttachment.getTexture().cast<TextureBase>();
|
||||
description.inputAttachments[description.numInputAttachments++] = tex->getView();
|
||||
}
|
||||
for (auto& colorAttachment : layout.colorAttachments) {
|
||||
PTexture2D tex = colorAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase tex = colorAttachment.getTexture().cast<TextureBase>();
|
||||
description.colorAttachments[description.numColorAttachments++] = tex->getView();
|
||||
}
|
||||
for (auto& resolveAttachment : layout.resolveAttachments) {
|
||||
PTexture2D tex = resolveAttachment.getTexture().cast<Texture2D>();
|
||||
description.resolveAttachments[description.numResolveAttachments++] = tex->getView();
|
||||
PTextureBase tex = resolveAttachment.getTexture().cast<TextureBase>();
|
||||
description.resolveAttachments[description.numResolveAttachments++] = tex->getView();
|
||||
}
|
||||
if (layout.depthAttachment.getTexture() != nullptr) {
|
||||
PTexture2D tex = layout.depthAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase tex = layout.depthAttachment.getTexture().cast<TextureBase>();
|
||||
description.depthAttachment = tex->getView();
|
||||
}
|
||||
if (layout.depthResolveAttachment.getTexture() != nullptr) {
|
||||
PTexture2D tex = layout.depthResolveAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase tex = layout.depthResolveAttachment.getTexture().cast<TextureBase>();
|
||||
description.depthResolveAttachment = tex->getView();
|
||||
}
|
||||
return CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32());
|
||||
@@ -244,23 +254,23 @@ uint32 RenderPass::getFramebufferHash() {
|
||||
|
||||
void RenderPass::endRenderPass() {
|
||||
for (auto& inputAttachment : layout.inputAttachments) {
|
||||
PTexture2D tex = inputAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase tex = inputAttachment.getTexture().cast<TextureBase>();
|
||||
tex->setLayout(inputAttachment.getFinalLayout());
|
||||
}
|
||||
for (auto& colorAttachment : layout.colorAttachments) {
|
||||
PTexture2D tex = colorAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase tex = colorAttachment.getTexture().cast<TextureBase>();
|
||||
tex->setLayout(colorAttachment.getFinalLayout());
|
||||
}
|
||||
for (auto& resolveAttachment : layout.resolveAttachments) {
|
||||
PTexture2D tex = resolveAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase tex = resolveAttachment.getTexture().cast<TextureBase>();
|
||||
tex->setLayout(resolveAttachment.getFinalLayout());
|
||||
}
|
||||
if (layout.depthAttachment.getTexture() != nullptr) {
|
||||
PTexture2D tex = layout.depthAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase tex = layout.depthAttachment.getTexture().cast<TextureBase>();
|
||||
tex->setLayout(layout.depthAttachment.getFinalLayout());
|
||||
}
|
||||
if (layout.depthResolveAttachment.getTexture() != nullptr) {
|
||||
PTexture2D tex = layout.depthResolveAttachment.getTexture().cast<Texture2D>();
|
||||
PTextureBase tex = layout.depthResolveAttachment.getTexture().cast<TextureBase>();
|
||||
tex->setLayout(layout.depthResolveAttachment.getFinalLayout());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ namespace Seele {
|
||||
namespace Vulkan {
|
||||
class RenderPass : public Gfx::RenderPass {
|
||||
public:
|
||||
RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, Gfx::PViewport viewport, std::string name);
|
||||
RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, URect viewport,
|
||||
std::string name, Array<uint32> viewMasks = {}, Array<uint32> correlationMasks = {});
|
||||
virtual ~RenderPass();
|
||||
uint32 getFramebufferHash();
|
||||
void endRenderPass();
|
||||
|
||||
@@ -29,10 +29,10 @@ VkImageAspectFlags getAspectFromFormat(Gfx::SeFormat format) {
|
||||
}
|
||||
|
||||
TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const TextureCreateInfo& createInfo, VkImage existingImage)
|
||||
: CommandBoundResource(graphics, createInfo.name), image(existingImage), owner(createInfo.sourceData.owner), width(createInfo.width),
|
||||
height(createInfo.height), depth(createInfo.depth), arrayCount(createInfo.elements), layerCount(createInfo.layers), mipLevels(1),
|
||||
samples(createInfo.samples), format(createInfo.format), usage(createInfo.usage),
|
||||
layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED), aspect(getAspectFromFormat(createInfo.format)), ownsImage(false) {
|
||||
: CommandBoundResource(graphics, createInfo.name), image(existingImage), imageView(VK_NULL_HANDLE), allocation(nullptr),
|
||||
owner(createInfo.sourceData.owner), width(createInfo.width), height(createInfo.height), depth(createInfo.depth),
|
||||
arrayCount(createInfo.elements), layerCount(createInfo.layers), mipLevels(1), samples(createInfo.samples), format(createInfo.format),
|
||||
usage(createInfo.usage), layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED), aspect(getAspectFromFormat(createInfo.format)), ownsImage(false) {
|
||||
if (createInfo.useMip) {
|
||||
mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(width, height)))) + 1;
|
||||
}
|
||||
@@ -95,7 +95,8 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const
|
||||
.pObjectName = name.c_str(),
|
||||
};
|
||||
vkSetDebugUtilsObjectNameEXT(graphics->getDevice(), &nameInfo);
|
||||
ownsImage = true;const DataSource& sourceData = createInfo.sourceData;
|
||||
ownsImage = true;
|
||||
const DataSource& sourceData = createInfo.sourceData;
|
||||
if (sourceData.size > 0) {
|
||||
changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_ACCESS_NONE, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
@@ -117,7 +118,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const
|
||||
vmaMapMemory(graphics->getAllocator(), stagingAlloc->allocation, &data);
|
||||
std::memcpy(data, sourceData.data, sourceData.size);
|
||||
vmaUnmapMemory(graphics->getAllocator(), stagingAlloc->allocation);
|
||||
|
||||
|
||||
PCommandPool commandPool = graphics->getQueueCommands(owner);
|
||||
VkBufferImageCopy region = {
|
||||
.bufferOffset = 0,
|
||||
@@ -138,10 +139,10 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const
|
||||
},
|
||||
.imageExtent = {.width = width, .height = height, .depth = depth},
|
||||
};
|
||||
|
||||
vkCmdCopyBufferToImage(commandPool->getCommands()->getHandle(), stagingAlloc->buffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
1, ®ion);
|
||||
|
||||
|
||||
vkCmdCopyBufferToImage(commandPool->getCommands()->getHandle(), stagingAlloc->buffer, image,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
||||
|
||||
commandPool->getCommands()->bindResource(PBufferAllocation(stagingAlloc));
|
||||
generateMipmaps();
|
||||
// When loading a texture from a file, we will almost always use it as a texture map for fragment shaders
|
||||
@@ -150,7 +151,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const
|
||||
graphics->getDestructionManager()->queueResourceForDestruction(std::move(stagingAlloc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VkImageViewCreateInfo viewInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
@@ -385,7 +386,10 @@ TextureBase::TextureBase(PGraphics graphics, VkImageViewType viewType, const Tex
|
||||
: handle(new TextureHandle(graphics, viewType, createInfo, existingImage)), graphics(graphics),
|
||||
initialOwner(createInfo.sourceData.owner) {}
|
||||
|
||||
TextureBase::~TextureBase() { graphics->getDestructionManager()->queueResourceForDestruction(std::move(handle)); }
|
||||
TextureBase::~TextureBase() {
|
||||
graphics->getDestructionManager()->queueResourceForDestruction(std::move(handle));
|
||||
handle = nullptr;
|
||||
}
|
||||
|
||||
void TextureBase::pipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess,
|
||||
VkPipelineStageFlags dstStage) {
|
||||
|
||||
@@ -6,15 +6,13 @@
|
||||
#include "Resources.h"
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
|
||||
namespace Seele {
|
||||
namespace Vulkan {
|
||||
class TextureHandle : public CommandBoundResource {
|
||||
public:
|
||||
TextureHandle(PGraphics graphics, VkImageViewType viewType, const TextureCreateInfo& createInfo, VkImage existingImage);
|
||||
virtual ~TextureHandle();
|
||||
void pipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess,
|
||||
VkPipelineStageFlags dstStage);
|
||||
void pipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess, VkPipelineStageFlags dstStage);
|
||||
void transferOwnership(Gfx::QueueType newOwner);
|
||||
void changeLayout(Gfx::SeImageLayout newLayout, VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess,
|
||||
VkPipelineStageFlags dstStage);
|
||||
@@ -37,11 +35,15 @@ class TextureHandle : public CommandBoundResource {
|
||||
VkImageAspectFlags aspect;
|
||||
uint8 ownsImage;
|
||||
};
|
||||
DECLARE_REF(TextureHandle)
|
||||
DEFINE_REF(TextureHandle)
|
||||
|
||||
DECLARE_REF(TextureBase)
|
||||
DECLARE_REF(Texture2D)
|
||||
DECLARE_REF(Texture3D)
|
||||
DECLARE_REF(TextureCube)
|
||||
class TextureBase {
|
||||
public:
|
||||
TextureBase(PGraphics graphics, VkImageViewType viewType, const TextureCreateInfo& createInfo,
|
||||
VkImage existingImage = VK_NULL_HANDLE);
|
||||
TextureBase(PGraphics graphics, VkImageViewType viewType, const TextureCreateInfo& createInfo, VkImage existingImage = VK_NULL_HANDLE);
|
||||
virtual ~TextureBase();
|
||||
uint32 getWidth() const { return handle->width; }
|
||||
uint32 getHeight() const { return handle->height; }
|
||||
@@ -58,13 +60,13 @@ class TextureBase {
|
||||
constexpr uint32 getMipLevels() const { return handle->mipLevels; }
|
||||
constexpr bool isDepthStencil() const { return handle->aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); }
|
||||
|
||||
void pipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess,
|
||||
VkPipelineStageFlags dstStage);
|
||||
void pipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess, VkPipelineStageFlags dstStage);
|
||||
void transferOwnership(Gfx::QueueType newOwner);
|
||||
void changeLayout(Gfx::SeImageLayout newLayout, VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess,
|
||||
VkPipelineStageFlags dstStage);
|
||||
void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer);
|
||||
void generateMipmaps();
|
||||
|
||||
protected:
|
||||
OTextureHandle handle;
|
||||
// Updates via reference
|
||||
|
||||
@@ -8,8 +8,7 @@ Window::Window() {}
|
||||
Window::~Window() {}
|
||||
|
||||
Viewport::Viewport(PWindow owner, const ViewportCreateInfo& viewportInfo)
|
||||
: sizeX(std::min(owner->getFramebufferWidth(), viewportInfo.dimensions.size.x)),
|
||||
sizeY(std::min(owner->getFramebufferHeight(), viewportInfo.dimensions.size.y)), offsetX(viewportInfo.dimensions.offset.x),
|
||||
: sizeX(viewportInfo.dimensions.size.x), sizeY(viewportInfo.dimensions.size.y), offsetX(viewportInfo.dimensions.offset.x),
|
||||
offsetY(viewportInfo.dimensions.offset.y), fieldOfView(viewportInfo.fieldOfView), owner(owner) {}
|
||||
|
||||
Viewport::~Viewport() {}
|
||||
|
||||
@@ -53,6 +53,12 @@ class Viewport {
|
||||
constexpr float getContentScaleX() const { return owner->getContentScaleX(); }
|
||||
constexpr float getContentScaleY() const { return owner->getContentScaleY(); }
|
||||
Matrix4 getProjectionMatrix() const;
|
||||
URect getRenderArea() const {
|
||||
return URect{
|
||||
.size = {sizeX, sizeY},
|
||||
.offset = {offsetX, offsetY},
|
||||
};
|
||||
}
|
||||
|
||||
protected:
|
||||
uint32 sizeX;
|
||||
|
||||
Reference in New Issue
Block a user