Graphics/FrameGraph: Add support for texture arrays
This commit is contained in:
parent
5b11e53d33
commit
b1487a04fd
|
|
@ -33,6 +33,8 @@ namespace Nz
|
|||
~FrameGraph() = default;
|
||||
|
||||
inline std::size_t AddAttachment(FramePassAttachment attachment);
|
||||
inline std::size_t AddAttachmentArray(FramePassAttachment attachment, std::size_t layerCount);
|
||||
inline std::size_t AddAttachmentArrayLayer(std::size_t attachmentId, std::size_t layerIndex);
|
||||
inline std::size_t AddAttachmentCube(FramePassAttachment attachment);
|
||||
inline std::size_t AddAttachmentCubeFace(std::size_t attachmentId, CubemapFace face);
|
||||
inline std::size_t AddAttachmentProxy(std::string name, std::size_t attachmentId);
|
||||
|
|
@ -55,6 +57,11 @@ namespace Nz
|
|||
using PassIdToPhysicalPassIndex = std::unordered_map<std::size_t /*passId*/, std::size_t /*physicalPassId*/>;
|
||||
using TextureBarrier = BakedFrameGraph::TextureBarrier;
|
||||
|
||||
struct AttachmentArray : FramePassAttachment
|
||||
{
|
||||
std::size_t layerCount;
|
||||
};
|
||||
|
||||
struct AttachmentCube : FramePassAttachment
|
||||
{
|
||||
};
|
||||
|
|
@ -103,6 +110,7 @@ namespace Nz
|
|||
std::vector<PhysicalPassData> physicalPasses;
|
||||
std::vector<FrameGraphTextureData> textures;
|
||||
std::vector<std::size_t> texture2DPool;
|
||||
std::vector<std::size_t> texture2DArrayPool;
|
||||
std::vector<std::size_t> textureCubePool;
|
||||
AttachmentIdToPassId attachmentLastUse;
|
||||
AttachmentIdToPassMap attachmentReadList;
|
||||
|
|
@ -128,7 +136,7 @@ namespace Nz
|
|||
void ReorderPasses();
|
||||
void TraverseGraph(std::size_t passIndex);
|
||||
|
||||
using AttachmentType = std::variant<FramePassAttachment, AttachmentProxy, AttachmentCube, AttachmentLayer>;
|
||||
using AttachmentType = std::variant<FramePassAttachment, AttachmentProxy, AttachmentArray, AttachmentCube, AttachmentLayer>;
|
||||
|
||||
std::vector<std::size_t> m_backbufferOutputs;
|
||||
std::vector<FramePass> m_framePasses;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,33 @@ namespace Nz
|
|||
return id;
|
||||
}
|
||||
|
||||
inline std::size_t FrameGraph::AddAttachmentArray(FramePassAttachment attachment, std::size_t layerCount)
|
||||
{
|
||||
AttachmentArray attachmentArray{ std::move(attachment) };
|
||||
attachmentArray.layerCount = layerCount;
|
||||
|
||||
std::size_t id = m_attachments.size();
|
||||
m_attachments.emplace_back(std::move(attachmentArray));
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
inline std::size_t FrameGraph::AddAttachmentArrayLayer(std::size_t attachmentId, std::size_t layerIndex)
|
||||
{
|
||||
attachmentId = ResolveAttachmentIndex(attachmentId);
|
||||
|
||||
assert(std::holds_alternative<AttachmentArray>(m_attachments[attachmentId]));
|
||||
assert(layerIndex < std::get<AttachmentArray>(m_attachments[attachmentId]).layerCount);
|
||||
|
||||
std::size_t id = m_attachments.size();
|
||||
m_attachments.emplace_back(AttachmentLayer{
|
||||
attachmentId,
|
||||
layerIndex
|
||||
});
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
inline std::size_t FrameGraph::AddAttachmentCube(FramePassAttachment attachment)
|
||||
{
|
||||
std::size_t id = m_attachments.size();
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ namespace Nz
|
|||
TextureUsageFlags usage;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
unsigned int layerCount;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -170,8 +170,9 @@ namespace Nz
|
|||
textureCreationParams.pixelFormat = textureData.format;
|
||||
textureCreationParams.levelCount = 1;
|
||||
|
||||
textureCreationParams.layerCount = textureData.layerCount;
|
||||
if (textureCreationParams.type == ImageType::Cubemap)
|
||||
textureCreationParams.layerCount = 6;
|
||||
textureCreationParams.layerCount *= 6;
|
||||
|
||||
textureCreationParams.width = 1;
|
||||
textureCreationParams.height = 1;
|
||||
|
|
|
|||
|
|
@ -258,6 +258,13 @@ namespace Nz
|
|||
assert(std::find(m_pending.texture2DPool.begin(), m_pending.texture2DPool.end(), textureId) == m_pending.texture2DPool.end());
|
||||
m_pending.texture2DPool.push_back(textureId);
|
||||
}
|
||||
else if (std::holds_alternative<AttachmentArray>(attachmentData))
|
||||
{
|
||||
std::size_t textureId = Retrieve(m_pending.attachmentToTextures, attachmentId);
|
||||
|
||||
assert(std::find(m_pending.textureCubePool.begin(), m_pending.textureCubePool.end(), textureId) == m_pending.textureCubePool.end());
|
||||
m_pending.texture2DArrayPool.push_back(textureId);
|
||||
}
|
||||
else if (std::holds_alternative<AttachmentCube>(attachmentData))
|
||||
{
|
||||
std::size_t textureId = Retrieve(m_pending.attachmentToTextures, attachmentId);
|
||||
|
|
@ -1014,6 +1021,49 @@ namespace Nz
|
|||
data.width = attachmentData.width;
|
||||
data.height = attachmentData.height;
|
||||
data.size = attachmentData.size;
|
||||
data.layerCount = 1;
|
||||
|
||||
return textureId;
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, AttachmentArray>)
|
||||
{
|
||||
const AttachmentArray& attachmentData = arg;
|
||||
|
||||
// Fetch from reuse pool if possible
|
||||
for (auto it = m_pending.texture2DArrayPool.begin(); it != m_pending.texture2DArrayPool.end(); ++it)
|
||||
{
|
||||
std::size_t textureId = *it;
|
||||
|
||||
FrameGraphTextureData& data = m_pending.textures[textureId];
|
||||
assert(data.type == ImageType::E2D_Array);
|
||||
|
||||
if (data.format != attachmentData.format ||
|
||||
data.width != attachmentData.width ||
|
||||
data.height != attachmentData.height ||
|
||||
data.size != attachmentData.size ||
|
||||
data.layerCount != attachmentData.layerCount)
|
||||
continue;
|
||||
|
||||
m_pending.textureCubePool.erase(it);
|
||||
m_pending.attachmentToTextures.emplace(attachmentIndex, textureId);
|
||||
|
||||
if (!attachmentData.name.empty() && data.name != attachmentData.name)
|
||||
data.name += " / " + attachmentData.name;
|
||||
|
||||
return textureId;
|
||||
}
|
||||
|
||||
std::size_t textureId = m_pending.textures.size();
|
||||
m_pending.attachmentToTextures.emplace(attachmentIndex, textureId);
|
||||
|
||||
FrameGraphTextureData& data = m_pending.textures.emplace_back();
|
||||
data.type = ImageType::E2D_Array;
|
||||
data.name = attachmentData.name;
|
||||
data.format = attachmentData.format;
|
||||
data.width = attachmentData.width;
|
||||
data.height = attachmentData.height;
|
||||
data.size = attachmentData.size;
|
||||
data.layerCount = attachmentData.layerCount;
|
||||
|
||||
return textureId;
|
||||
}
|
||||
|
|
@ -1054,6 +1104,7 @@ namespace Nz
|
|||
data.width = attachmentData.width;
|
||||
data.height = attachmentData.height;
|
||||
data.size = attachmentData.size;
|
||||
data.layerCount = 1;
|
||||
|
||||
return textureId;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue