From ea47f0bd87e835e0bc287ecfda27083e6ffc2607 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 12 Aug 2019 18:34:26 -0700 Subject: [PATCH] simplify how we determine if a resource is sample-able --- filament/src/fg/FrameGraph.cpp | 16 ++++++++++------ filament/src/fg/FrameGraphResource.h | 2 +- filament/src/fg/fg/PassNode.h | 2 +- filament/src/fg/fg/Resource.cpp | 6 ++---- filament/src/fg/fg/Resource.h | 1 - 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/filament/src/fg/FrameGraph.cpp b/filament/src/fg/FrameGraph.cpp index d483739bfd..f6ccff09e4 100644 --- a/filament/src/fg/FrameGraph.cpp +++ b/filament/src/fg/FrameGraph.cpp @@ -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"; } diff --git a/filament/src/fg/FrameGraphResource.h b/filament/src/fg/FrameGraphResource.h index f6c0609477..fffb72ad1e 100644 --- a/filament/src/fg/FrameGraphResource.h +++ b/filament/src/fg/FrameGraphResource.h @@ -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::max(); // index to the resource handle diff --git a/filament/src/fg/fg/PassNode.h b/filament/src/fg/fg/PassNode.h index f4b0b9f163..c3bf3fff53 100644 --- a/filament/src/fg/fg/PassNode.h +++ b/filament/src/fg/fg/PassNode.h @@ -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. diff --git a/filament/src/fg/fg/Resource.cpp b/filament/src/fg/fg/Resource.cpp index 36335a796b..0bc7e78ee6 100644 --- a/filament/src/fg/fg/Resource.cpp +++ b/filament/src/fg/fg/Resource.cpp @@ -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); } } diff --git a/filament/src/fg/fg/Resource.h b/filament/src/fg/fg/Resource.h index f34f1c3dca..c38c2251b0 100644 --- a/filament/src/fg/fg/Resource.h +++ b/filament/src/fg/fg/Resource.h @@ -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()