在运行时调度节点中的工作
daBfg API 的总体目标是为你做尽可能多的模板工作。
它可以自动管理资源、将资源绑定到着色器变量等。
不过,在将传统代码移植到 daBfg 时,通常需要通过直接访问 FG 管理的纹理和缓冲区来自行完成部分工作。
在处理 CPU blob 时,从它们内部获取数据往往是首要问题。
为方便起见,可以使用 dabfg::VirtualResourceRequest::handle() 方法在声明回调中提取资源句柄。
然后应在执行回调中捕获该句柄并进行引用,以访问封装物理 GPU 资源的 ManagedResView 及其 D3DRESID(通过在引擎资源管理器中注册获得)。
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(); // 只有在指定阶段/用途后才能调用
return [texHndl]()
{
legacy_code(texHndl.view());
};
});
下面是 VirtualResourceHandle 类的完整文档。
-
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.