simplify how we determine if a resource is sample-able

This commit is contained in:
Mathias Agopian
2019-08-12 18:34:26 -07:00
committed by Mathias Agopian
parent b849008ce5
commit ea47f0bd87
5 changed files with 14 additions and 13 deletions

View File

@@ -73,7 +73,10 @@ FrameGraphResource::Descriptor const& FrameGraph::Builder::getDescriptor(FrameGr
bool FrameGraph::Builder::isAttachment(FrameGraphResource resource) const noexcept {
ResourceNode& node = mFrameGraph.getResource(resource);
return node.renderTargetIndex != ResourceNode::UNINITIALIZED;
return node.resource->usage & (
TextureUsage::COLOR_ATTACHMENT |
TextureUsage::DEPTH_ATTACHMENT |
TextureUsage::STENCIL_ATTACHMENT);
}
FrameGraphRenderTarget::Descriptor const&
@@ -121,7 +124,7 @@ void FrameGraph::Builder::createRenderTarget(const char* name,
if (attachmentInfo.isValid()) {
ResourceNode& node = fg.getResource(attachmentInfo.getHandle());
// figure out the attachment flags (could this be done later?)
// figure out the attachment flags
uint8_t usage = node.resource->usage;
usage |= usages[i];
node.resource->usage = TextureUsage(usage);
@@ -503,8 +506,8 @@ FrameGraph& FrameGraph::compile() noexcept {
for (PassNode& pass : passNodes) {
// passes that were reading from "from node", now read from "to node" as well
for (FrameGraphResource handle : pass.reads) {
if (handle.index == alias.from.index) {
sratch.push_back(alias.to.index);
if (handle == alias.from) {
sratch.push_back(alias.to);
}
}
pass.reads.insert(pass.reads.end(), sratch.begin(), sratch.end());
@@ -513,7 +516,7 @@ FrameGraph& FrameGraph::compile() noexcept {
// Passes that were writing to "from node", no longer do
pass.writes.erase(
std::remove_if(pass.writes.begin(), pass.writes.end(),
[&alias](auto handle) { return handle.index == alias.from.index; }),
[&alias](auto handle) { return handle == alias.from; }),
pass.writes.end());
}
}
@@ -747,7 +750,7 @@ void FrameGraph::export_graphviz(utils::io::ostream& out) {
out << "\"R" << node.resource->id << "_" << +node.version << "\""
"[label=\"" << node.resource->name << "\\n(version: " << +node.version << ")"
"\\nid:" << node.resource->id <<
"\\nrefs:" << node.resource->refs << ", texture: " << node.resource->needsTexture <<
"\\nrefs:" << node.resource->refs << ", texture: " << bool(node.resource->usage & TextureUsage::SAMPLEABLE) <<
"\", style=filled, fillcolor="
<< ((subresource->imported) ?
(node.resource->refs ? "palegreen" : "palegreen4") :
@@ -761,6 +764,7 @@ void FrameGraph::export_graphviz(utils::io::ostream& out) {
out << "P" << node.id << " -> { ";
for (auto const& writer : node.writes) {
out << "R" << registry[writer.index].resource->id << "_" << +registry[writer.index].version << " ";
out << "R" << registry[writer.index].resource->id << "_" << +registry[writer.index].version << " ";
}
out << "} [color=red2]\n";
}

View File

@@ -49,7 +49,7 @@ class FrameGraphResource {
friend struct fg::RenderTarget;
friend struct fg::RenderTargetResource;
FrameGraphResource(uint16_t index) noexcept : index(index) {}
explicit FrameGraphResource(uint16_t index) noexcept : index(index) {}
static constexpr uint16_t UNINITIALIZED = std::numeric_limits<uint16_t>::max();
// index to the resource handle

View File

@@ -56,7 +56,7 @@ struct PassNode { // 200
ResourceNode const& node = fg.getResource(handle);
if (!isRenderTarget) {
node.resource->needsTexture = true;
node.resource->usage |= backend::TextureUsage::SAMPLEABLE;
}
// don't allow multiple reads of the same resource -- it's just redundant.

View File

@@ -44,13 +44,11 @@ void Resource::create(FrameGraph& fg) noexcept {
assert(usage);
// (it means it's only used as an attachment for a rendertarget)
uint8_t samples = desc.samples;
auto effectiveUsage = usage;
if (needsTexture) {
effectiveUsage |= TextureUsage::SAMPLEABLE;
if (usage & TextureUsage::SAMPLEABLE) {
samples = 1; // sampleable textures can't be multi-sampled
}
texture = fg.getResourceAllocator().createTexture(name, desc.type, desc.levels,
desc.format, samples, desc.width, desc.height, desc.depth, effectiveUsage);
desc.format, samples, desc.width, desc.height, desc.depth, usage);
}
}

View File

@@ -52,7 +52,6 @@ struct Resource final : public VirtualResource { // 72
// updated by builder
uint8_t version = 0;
backend::TextureUsage usage = (backend::TextureUsage)0;
bool needsTexture = false;
FrameGraphResource::Descriptor desc;
// computed during compile()