Dispatching Work in Nodes at Runtime
The general aim of the daBfg API is to do as much boiler-plate stuff for you as possible.
It can automatically manage resources, bind them to shader vars, etc.
However, when porting legacy code to daBfg, it is often necessary to do some of the work yourself by getting direct access to FG-managed textures and buffers.
When working with CPU blobs, getting the data from inside them is often the primary concern.
To facilitate this, it is possible to extract a handle to a resource inside the declaration callback using the dabfg::VirtualResourceRequest::handle()
method.
This handle should then be captured inside the execution callback and dereferenced to get access to the ManagedResView encapsulating a physical GPU resource and it’s D3DRESID (acquired by registering it within the engine resource manager).
auto handle = dabfg::register_node("node_name", DABFG_PP_NODE_SRC,
[](dabfg::Registry registry)
{
auto texHndl = registry.read("my_tex")
.texture()
.atStage(dabfg::Stage::PS)
.useAs(dabfg::Usage::SHADER_RESOURCE)
.handle(); // Is only callable after the stage/usage were specified
return [texHndl]()
{
legacy_code(texHndl.view());
};
});
Below is the full documentation of the VirtualResourceHandle class.
-
template<class Res, bool gpu, bool optional>
class VirtualResourceHandle Handle to a virtual resource managed by BFG. Does not actually represent a physical GPU or CPU resource until the execution callback gets called. The physical resource will also change between calls to the execution callback, so the dereferenced value of this handle should NEVER be cached anywhere.
All methods are const & as this is supposed to be called from within the node execution callback.
- Template Parameters
Res – BaseTexture or Sbuffer when
gpu
== true, otherwise arbitrary CPU data type.gpu – True iff this handle represents a GPU resource.
optional – True iff this handle can refer to a missing resource.
Public Functions
-
inline Res &ref() const &
Returns a reference to the provided resource. Only defined for mandatory handles.
For read requests, this always returns a const reference. Due to unfortunate coupling of textures with samplers, sometimes this constness needs to be violated. Use
.view()
for that.- Returns
A non-nullable reference to the resource.
-
inline Res *get() const &
Returns a pointer to the provided resource, or nullptr for missing optional resources. Always check for null when using this!
For read requests, this always returns a const reference. Due to unfortunate coupling of textures with samplers, sometimes this constness needs to be violated. Use
.view()
for that.- Returns
A pointer to the resource that may be nullptr for optional requests.
-
inline View view() const &
Returns a managed view to a provided GPU resource, or an empty view for missing optional resources.
- Returns
A ManagedResView to the GPU resource that may be empty for optional requests.
-
inline D3DRESID d3dResId() const &
Returns the engine resource manager ID for a provided GPU resource, or a BAD_RESID for a missing optional resource.
- Returns
A D3DRESID to the GPU resource that may be BAD_RESID for optional requests.