Class ParameterBlockReflection

Synopsis

#include <Source/Falcor/Core/Program/ProgramReflection.h>

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

Description

A reflection object describing a parameter block

Inheritance

Ancestors: std::enable_shared_from_this< ParameterBlockReflection >

Decsendents: EntryPointGroupReflection

Structures

DefaultConstantBufferBindingInfo
DescriptorSetInfoInformation on how a particular descriptor set should be filled in.
ResourceRangeBindingInfoDescribes binding information for a resource range.

Methods

ParameterBlockReflection
addResourceRange
createCreate a new parameter block reflector, for the given element type.
createEmpty
finalize
findMember
getDefaultConstantBufferBindingInfo
getDescriptorSetCountGet the number of descriptor sets that are needed for an object of this type.
getDescriptorSetInfo
getDescriptorSetLayoutGet the layout for the indexth descriptor set that needs to be created for an object of this type.
getElementTypeGet the type of the contents of the parameter block.
getParameterBlockSubObjectRangeCount
getParameterBlockSubObjectRangeIndex
getProgramVersion
getResourceGet the variable for a resource in the block
getResourceBindingGet the bind-location for a resource in the block
getResourceRange
getResourceRangeBindingInfoGet binding information on a contained descriptor range.
getResourceRangeCountGet the number of descriptor ranges contained in this type.
getRootDescriptorRangeCount
getRootDescriptorRangeIndex
hasDefaultConstantBuffer
setDefaultConstantBufferBindingInfo
setElementType

Source

Lines 1201-1418 in Source/Falcor/Core/Program/ProgramReflection.h.

class dlldecl ParameterBlockReflection : public std::enable_shared_from_this<ParameterBlockReflection>
{
public:
    using SharedPtr = std::shared_ptr<ParameterBlockReflection>;
    using SharedConstPtr = std::shared_ptr<const ParameterBlockReflection>;
    static const uint32_t kInvalidIndex = 0xffffffff;
    /** Create a new parameter block reflector, for the given element type.
    */
    static SharedPtr create(
        ProgramVersion const* pProgramVersion,
        ReflectionType::SharedConstPtr const& pElementType);
    /** Create a new shader object reflector, for the given element type.
    */
    static SharedPtr create(
        ProgramVersion const* pProgramVersion,
        slang::TypeLayoutReflection* pElementType);
    /** Get the type of the contents of the parameter block.
    */
    ReflectionType::SharedConstPtr getElementType() const { return mpElementType; }
    using BindLocation = TypedShaderVarOffset;
    // TODO(tfoley): The following two functions really pertain to members, not just resources.
    /** Get the variable for a resource in the block
    */
    const ReflectionVar::SharedConstPtr getResource(const std::string& name) const;
    /** Get the bind-location for a resource in the block
    */
    BindLocation getResourceBinding(const std::string& name) const;
    /// Information on how a particular descriptor set should be filled in.
    ///
    /// A single `ParameterBlock` may map to zero or more distinct descriptor
    /// sets, depending on what members it contains, and how those members
    /// are mapped to API registers/spaces.
    ///
    struct DescriptorSetInfo
    {
        /// The layout of the API descriptor set to allocate.
        DescriptorSet::Layout   layout;
        /// The indices of resource ranges within the parameter block
        /// to bind to the descriptor ranges of the above set.
        ///
        /// The order of entries in the `resourceRangeIndices`
        /// array will correspond to the order of the corresponding
        /// descriptor ranges in the `layout`.
        ///
        std::vector<uint32_t>   resourceRangeIndices;
        /// Information about a sub-object that should have some
        /// of its resource ranges bound into this descriptor set.
        ///
        struct SubObjectInfo
        {
            /// The index of the resource range that defines the
            /// sub-object.
            ///
            uint32_t resourceRangeIndexOfSubObject;
            /// The set index within the sub-object for which
            /// data should be written into this set.
            ///
            uint32_t setIndexInSubObject;
        };
        /// All of the sub-objects of this parameter block that should
        /// have data written into this descriptor sets.
        ///
        std::vector<SubObjectInfo> subObjects;
    };
    /** Get the number of descriptor sets that are needed for an object of this type.
    */
    uint32_t getDescriptorSetCount() const { return (uint32_t) mDescriptorSets.size(); }
    const DescriptorSetInfo& getDescriptorSetInfo(uint32_t index) const { return mDescriptorSets[index]; }
    /** Get the layout for the `index`th descriptor set that needs to be created for an object of this type.
    */
    const DescriptorSet::Layout& getDescriptorSetLayout(uint32_t index) const { return mDescriptorSets[index].layout; }
    /** Describes binding information for a resource range.
    The resource ranges of a parameter block mirror those of its element type 1-to-1.
    Things like the descriptor type and count for a range can thus be queried on
    the element type, while the `ParameterBlockReflection` stores additional information
    pertinent to how resource ranges are bound to the pipeline state.
    */
    struct ResourceRangeBindingInfo
    {
        enum class Flavor
        {
            Simple,         ///< A simple resource range (texture/sampler/etc.)
            RootDescriptor, ///< A resource root descriptor (buffers only)
            ConstantBuffer, ///< A sub-object for a constant buffer
            ParameterBlock, ///< A sub-object for a parameter block
            Interface,      ///< A sub-object for an interface-type parameter
        };
        Flavor flavor = Flavor::Simple;
        uint32_t regIndex = 0;          ///< The register index
        uint32_t regSpace = 0;          ///< The register space
        uint32_t descriptorSetIndex = kInvalidIndex;    ///< The index of the descriptor set to be bound into, when flavor is Flavor::Simple.
        /// The reflection object for a sub-object range.
        ParameterBlockReflection::SharedConstPtr pSubObjectReflector;
        bool isDescriptorSet() const { return flavor == Flavor::Simple; }
        bool isRootDescriptor() const { return flavor == Flavor::RootDescriptor; }
    };
    struct DefaultConstantBufferBindingInfo
    {
        uint32_t regIndex = 0;          ///< The register index
        uint32_t regSpace = 0;          ///< The register space
        uint32_t descriptorSetIndex = kInvalidIndex;    ///< The index of the descriptor set to be bound into
        bool useRootConstants = false;
    };
    static SharedPtr createEmpty(
        ProgramVersion const* pProgramVersion);
    void setElementType(
        ReflectionType::SharedConstPtr const& pElementType);
    void addResourceRange(
        ResourceRangeBindingInfo const& bindingInfo);
    friend struct ParameterBlockReflectionFinalizer;
    void finalize();
    bool hasDefaultConstantBuffer() const;
    void setDefaultConstantBufferBindingInfo(DefaultConstantBufferBindingInfo const& info);
    DefaultConstantBufferBindingInfo const& getDefaultConstantBufferBindingInfo() const;
    /** Get the number of descriptor ranges contained in this type.
    */
    uint32_t getResourceRangeCount() const { return (uint32_t) mResourceRanges.size(); }
    ReflectionType::ResourceRange const& getResourceRange(uint32_t index) const { return getElementType()->getResourceRange(index); }
    /** Get binding information on a contained descriptor range.
    */
    ResourceRangeBindingInfo const& getResourceRangeBindingInfo(uint32_t index) const { return mResourceRanges[index]; }
    uint32_t getRootDescriptorRangeCount() const { return (uint32_t)mRootDescriptorRangeIndices.size(); }
    uint32_t getRootDescriptorRangeIndex(uint32_t index) const { return mRootDescriptorRangeIndices[index]; }
    uint32_t getParameterBlockSubObjectRangeCount() const { return (uint32_t) mParameterBlockSubObjectRangeIndices.size(); }
    uint32_t getParameterBlockSubObjectRangeIndex(uint32_t index) const { return mParameterBlockSubObjectRangeIndices[index]; }
    std::shared_ptr<const ProgramVersion> getProgramVersion() const;
    std::shared_ptr<const ReflectionVar> findMember(const std::string& name) const
    {
        return getElementType()->findMember(name);
    }
protected:
    ParameterBlockReflection(
        ProgramVersion const* pProgramVersion);
private:
    /// The element type of the parameter block
    ///
    /// For a `ConstantBuffer<T>` or `ParameterBlock<T>`,
    /// this will be the type `T`.
    ///
    ReflectionType::SharedConstPtr mpElementType;
    /// Binding information for the "default" constant buffer, if needed.
    ///
    DefaultConstantBufferBindingInfo mDefaultConstantBufferBindingInfo;
    /// Binding information for the resource ranges in the element type.
    ///
    /// For something like a `Texture2D` in the element type,
    /// this will record the corresponding `register` and `space`.
    ///
    std::vector<ResourceRangeBindingInfo> mResourceRanges;
    /// Layout and binding information for all descriptor sets that
    /// must be created to represent the state of a parameter block
    /// using this reflector.
    ///
    /// Note: this array does *not* include information for descriptor
    /// sets that correspond to `ParameterBlock` sub-objects, since
    /// they are required to allocate and maintain their own
    /// descriptor sets that this object can simply re-use.
    ///
    std::vector<DescriptorSetInfo> mDescriptorSets;
    /// Indices of the resource ranges that represent root descriptors,
    /// and which therefore need their resources to be bound to the root signature.
    ///
    /// Note: this array does *not* include information for root descriptors
    /// that correspond to `ParameterBlock` and `ConstantBuffer` sub-objects, since they
    /// are required to allocate and maintain their own root descriptor range indices.
    ///
    std::vector<uint32_t> mRootDescriptorRangeIndices;
    /// Indices of the resource ranges that represent parameter blocks,
    /// and which therefore need their descriptor sets to be bound
    /// along with the descriptor sets directly stored on the parameter block
    ///
    std::vector<uint32_t> mParameterBlockSubObjectRangeIndices;
    ProgramVersion const* mpProgramVersion = nullptr;
};





Add Discussion as Guest

Log in to DocsForge