AEJoy —— AE 插件开发中的 SmartFX (十)

340 阅读2分钟

「这是我参与11月更文挑战的第 20 天,活动详情查看:2021最后一次更文挑战」。

参加该活动的第 37 篇文章

正文

何时访问层参数

非层输入的参数可以在任何点自由检出(check out)。层输入必须在以下期间内访问: PF_Cmd_SMART_PRE_RENDER

effect-basics/command-selectors.frame-selectors 章节中提到 PF_Cmd_SMART_PRE_RENDER

仅限于 SmartFX。根据 effect 实现的任何标准,确定 effect 所需要产生其输出的输入区域

可能在 MediaCore 托管时发送两次。第一个将在 GetFrameDependencies 期间收集输入。

源检出可以在这里返回完整的帧尺寸。一旦渲染了源,如果它们的大小与第一次调用不同,那么这个选择器将使用实际的源大小第二次发出,以获得正确的输出大小。

注意,MediaCore 需要所有的输出,因此将使用 PF_PreRenderOutput::max_result_rect

16.0 的新特性

PF_PreRenderOutput 中将 PF_RenderOutputFlag_GPU_RENDER_POSSIBLE 设置为 GPU 渲染。

如果没有设置此标志,则由于参数或渲染设置的原因,请求的渲染无法使用所请求的 GPU 。

主机可能会使用另一个 what_gpu 选项(或 PF_GPU_Framework_None )来重新调用 PreRender

typedef struct {
  PF_RenderRequest  output_request; // what the effect is being asked to render
  short             bitdepth;       // bitdepth the effect is being driven in (in bpc)
  const             void *gpu_data; // (new AE 16.0)
  PF_GPU_Framework  what_gpu;       // (new AE 16.0)
  A_u_long          device_index;   // (new AE 16.0) For use in conjunction with PrSDKGPUDeviceSuite
} PF_PreRenderInput;

然而,您并不需要实际使用每一个输入。

如果你在 PF_Cmd_SMART_PRE_RENDER 中检出一个帧(或其中的一部分),并且没有随后在 PF_Cmd_SMART_RENDER 中检出它,它就永远不需要被渲染,极大地提高了性能

When To Access Layer Parameters

Parameters other than layer inputs may be freely checked out at any point. Layer inputs must be accessed during:ref:PF_Cmd_SMART_PRE_RENDER <effect-basics/command-selectors.frame-selectors>.

However, you aren’t required to actually use every input.

If you check out a frame (or portion thereof) in PF_Cmd_SMART_PRE_RENDER and do not subsequently check it out in PF_Cmd_SMART_RENDER, it need never be rendered, greatly improving performance.

等等,把那一层还给我!

checkout_layer_pixels 只能用之前在 PreRender 中使用的 checkout_id 调用一次。在 PreRenderSmartRender 中,检出的数量必须是一对一的映射。如果您需要多次检出一个层的像素(可能是因为代码的结构),只需使用多个 checkout_id 。在 PreRender 中,用各个不同的 checkout_id 在同一层调用 checkout_layer 。然后在 SmartRender 中,每次调用 checkout_layer_pixels 时,使用其中不同的一个 checkout_ids 。

Wait, Gimme That Layer Back!

checkout_layer_pixels can only be called once with the checkout_id used earlier in PreRender. There has to be a one-to-one mapping on the number of checkouts made in PreRender and SmartRender. If you need to check out the pixels of a layer more than once, perhaps because of the structure of your code, just use more than one checkout_id. In PreRender, call checkout_layer on the same layer with different unique checkout_ids. Then in SmartRender, use a different one of those checkout_ids each time checkout_layer_pixels is called in SmartRender.