Class ResourceCache

Synopsis

#include <Source/Falcor/RenderGraph/ResourceCache.h>

class dlldecl ResourceCache : public std::enable_shared_from_this<ResourceCache>

Description

No description yet.

Inheritance

Ancestors: std::enable_shared_from_this< ResourceCache >

Structures

DefaultPropertiesProperties to use during resource creation when its property has not been fully specified.

Methods

allocateResourcesAllocate all resources that need to be created/updated
createCreate a new object
getResourceGet a resource by name
getResourceReflectionGet the field-reflection of a resource
registerExternalResourceAdd/Remove reference to a graph input resource not owned by the cache
registerFieldRegister a field that requires resources to be allocated.
resetClears all registered field/resource properties and allocated resources.

Source

Lines 34-102 in Source/Falcor/RenderGraph/ResourceCache.h.

class dlldecl ResourceCache : public std::enable_shared_from_this<ResourceCache>
{
public:
    using SharedPtr = std::shared_ptr<ResourceCache>;
    using ResourcesMap = std::unordered_map<std::string, Resource::SharedPtr>;
    /** Create a new object
    */
    static SharedPtr create();
    /** Properties to use during resource creation when its property has not been fully specified.
    */
    struct DefaultProperties
    {
        uint2 dims;                                         ///< Width, height of the swap chain
        ResourceFormat format = ResourceFormat::Unknown;    ///< Format to use for texture creation
    };
    /** Add/Remove reference to a graph input resource not owned by the cache
        \param[in] name The resource's name
        \param[in] pResource The resource to register. If this is null, will unregister the resource
    */
    void registerExternalResource(const std::string& name, const Resource::SharedPtr& pResource);
    /** Register a field that requires resources to be allocated.
        \param[in] name String in the format of PassName.FieldName
        \param[in] field Reflection data for the field
        \param[in] timePoint The point in time for when this field is used. Normally this is an index into the execution order.
        \param[in] alias Optional. Another field name described in the same way as 'name'.
            If specified, and the field exists in the cache, the resource will be aliased with 'name' and field properties will be merged.
    */
    void registerField(const std::string& name, const RenderPassReflection::Field& field, uint32_t timePoint, const std::string& alias = "");
    /** Get a resource by name. Includes external resources known by the cache.
    */
    const Resource::SharedPtr& getResource(const std::string& name) const;
    /** Get the field-reflection of a resource
    */
    const RenderPassReflection::Field& getResourceReflection(const std::string& name) const;
    /** Allocate all resources that need to be created/updated.
        This includes new resources, resources whose properties have been updated since last allocation call.
    */
    void allocateResources(const DefaultProperties& params);
    /** Clears all registered field/resource properties and allocated resources.
    */
    void reset();
private:
    ResourceCache() = default;
    struct ResourceData
    {
        RenderPassReflection::Field field;      // Holds merged properties for aliased resources
        std::pair<uint32_t, uint32_t> lifetime; // Time range where this resource is being used
        Resource::SharedPtr pResource;          // The resource
        bool resolveBindFlags;                  // Whether or not we should resolve the field's bind-flags before creating the resource
        std::string name;                       // Full name of the resource, including the pass name
    };
    // Resources and properties for fields within (and therefore owned by) a render graph
    std::unordered_map<std::string, uint32_t> mNameToIndex;
    std::vector<ResourceData> mResourceData;
    // References to output resources not to be allocated by the render graph
    ResourcesMap mExternalResources;
};





Add Discussion as Guest

Log in to DocsForge