AEJoy —— AE 插件开发中的 命令选择器(五)

368 阅读5分钟

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

参加该活动的第 42 篇文章

正文

消息收发

(上接)

PF_Cmd_GET_EXTERNAL_DEPENDENCIES

只在 PF_Cmd_GLOBAL_SETUP 期间设置了 PF_OutFlag_I_HAVE_EXTERNAL_DEPENDENCIES 时发送。用插件依赖关系的描述填充一个字符串句柄(在 PF_ExtDependenciesExtra 中由 extra 所指向),确保为终止 NULL 字符分配了空间。如果没有需要报告的依赖项,返回一个 NULL 指针作为字符串句柄。如果检查类型是 PF_DepCheckType_ALL_DEPENDENCIES,则报告插件渲染可能需要的所有内容。如果检查类型是 PF_DepCheckType_MISSING_DEPENDENCIES ,则只报告缺失的项(如果什么都没有丢失,则报告一个空字符串)。

PF_Cmd_COMPLETELY_GENERAL

响应 AEGP 。额外的参数指向 AEGP 发送的任何参数。AEGP 只能与响应这个选择器的效果进行通信。

PF_Cmd_QUERY_DYNAMIC_FLAGS

只发送给在 PF_OutFlags2 中指定了PF_OutFlag2_SUPPORTS_QUERY_DYNAMIC_FLAGS 的插件,在它们的 PiPL 并在 PF_Cmd_GLOBAL_SETUP 期间。对于所有的动态标志,如果你要在这个命令期间改变它们,你必须在 PF_Cmd_GLOBAL_SETUP 期间设置标志。这个选择器将在任意时间被发送。作为响应,effect 应该使用 PF_CHECKOUT_PARAM 来访问它的(非层)参数,并决定是否应该设置任何支持 PF_Cmd_QUERY_DYNAMIC_FLAGS 的标志,例如:

  • PF_OutFlag_NON_PARAM_VARY
  • PF_OutFlag_PIX_INDEPENDENT
  • PF_OutFlag_I_USE_SHUTTER_ANGLE
  • PF_OutFlag2_I_USE_3D_CAMERA
  • PF_OutFlag2_I_USE_3D_LIGHTS
  • PF_OutFlag2_DOESNT_NEED_EMPTY_PIXELS
  • PF_OutFlag2_REVEALS_ZERO_ALPHA
  • PF_OutFlag2_DEPENDS_ON_UNREFERENCED_MASKS
  • PF_OutFlag2_OUTPUT_IS_WATERMARKED

After Effects 使用这些信息进行缓存和优化,所以要尽可能快地响应。

PF_Cmd_GPU_DEVICE_SETUP

这个选择器可以在任何时候被主机调用。对于每个 GPU 设备,它只会被调用一次。多个 GPU 设备可能同时处于 setup 状态。它将在 GlobalSetup 之后和 SequencSetup 之前被调用。这样做的目的是让效果在必要时进行 GPU 初始化,并让效果有机会仅基于该设备的属性而不是任何渲染上下文(帧大小等)来选择退出 GPU 设备。如果效果拒绝 GPU 设备,它将被 CPU 渲染所调用。PF_InData::what_gpu != PF_GPU_Framework_None 是预期的。如果支持 what_gpu 中的设备和框架,效果将在 PF_OutData::out_flags2 中设置一个或两个 PF_OutFlag2_SUPPORTS_GPU_RENDER_Fxx 标志。注意,只有PF_OutFlag2_SUPPORTS_GPU_RENDER_F32 将在 AE 16.0 中。没有在这里设置标志的效果将不会被认为支持这些设备的 GPU 渲染。PF_GPUDeviceSetupOutput::gpu_data 是插件拥有的指针,必须通过 PF_Cmd_GPU_DEVICE_SETDOWN 选择器释放。该指针在渲染时也可用。

PF_Cmd_GPU_DEVICE_SETDOWN

释放所有与 gpu_data 关联的资源。在 AE 中,这将在 GPU 设备发布之前调用。

typedef struct
{
    void *gpu_data; // effect 必须负责释放
    PF_GPU_Framework what_gpu;
    A_u_long device_index; // 与 PrSDKGPUDeviceSuite 一起使用
} PF_GPUDeviceSetdownInput;

typedef struct
{
    PF_GPUDeviceSetdownInput input;
} PF_GPUDeviceSetdownExtra;

PF_Cmd_GPU_SMART_RENDER_GPU

GPU 等价于现有的 PF_Cmd_SMART_RENDER 选择器。在渲染时,PF_Cmd_SMART_RENDERPF_Cmd_SMART_RENDER_GPU 选择器将被调用,这取决于预期的效果是产生 CPU 帧还是 GPU 帧作为输出。当 what_gpu != PF_GPU_Framework_None ,并对任何输入/输出的 PF_LayerDef 有效果时, 将只调用 PF_Cmd_SMART_RENDER_GPU 。当这个选择器在运行时,所有的帧检入和检出都将在 GPU 帧上操作。注意PF_Cmd_SMART_RENDER 共享 Extra 结构体。

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)
    void *pre_render_data;           // passed back from value placed in extra->output->pre_render_data during PF_Cmd_PRE_RENDER
    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)
} PF_SmartRenderInput;

typedef struct
{
    PF_SmartRenderInput *input;
    PF_SmartRenderCallbacks *cb;
} PF_SmartRenderExtra;

what_gpudevice_index 字段是 GPU 相关选择器的额外输入,指示插件进行渲染所使用的 GPU 框架。输入和输出缓冲区将在这个框架和设备上准备。设备、上下文、命令队列和其他相关的 GPU 状态可以通过PrSDKGPUDeviceSuite::GetDeviceInfo查询。what_gpuPF_Cmd_SMART_PRE_RENDERPF_Cmd_SMART_RENDER_GPU 选择器调用之间是相同的。

Messaging

PF_Cmd_GET_EXTERNAL_DEPENDENCIES

Only sent if PF_OutFlag_I_HAVE_EXTERNAL_DEPENDENCIES was set during PF_Cmd_GLOBAL_SETUP.Populate a string handle (in the PF_ExtDependenciesExtra pointed to by extra) with a description of your plug-in’s dependencies, making sure to allocate space for the terminating NULL character.Return just a NULL pointer for the string handle if there are no dependencies to report.If the check type is PF_DepCheckType_ALL_DEPENDENCIES, report everything that might be required for your plug-in to render.Report only missing items (or a null string if nothing’s missing) if the check type is PF_DepCheckType_MISSING_DEPENDENCIES.

PF_Cmd_COMPLETELY_GENERAL

Respond to an AEGP. The extra parameter points to whatever parameter the AEGP sent.AEGPs can only communicate with effects which respond to this selector.

PF_Cmd_QUERY_DYNAMIC_FLAGS

Sent only to plug-ins which have specified PF_OutFlag2_SUPPORTS_QUERY_DYNAMIC_FLAGS in PF_OutFlags2, in their PiPL and during PF_Cmd_GLOBAL_SETUP.With all of the dynamic flags, if you will ever change them during this command, you must have set the flag on during PF_Cmd_GLOBAL_SETUP.This selector will be sent at arbitrary times.In response, the effect should access its (non-layer) parameters using PF_CHECKOUT_PARAM, and decide whether any of the flags that support PF_Cmd_QUERY_DYNAMIC_FLAGS should be set, such as:> - PF_OutFlag_WIDE_TIME_INPUT

  • PF_OutFlag_NON_PARAM_VARY
  • PF_OutFlag_PIX_INDEPENDENT
  • PF_OutFlag_I_USE_SHUTTER_ANGLE
  • PF_OutFlag2_I_USE_3D_CAMERA
  • PF_OutFlag2_I_USE_3D_LIGHTS
  • PF_OutFlag2_DOESNT_NEED_EMPTY_PIXELS
  • PF_OutFlag2_REVEALS_ZERO_ALPHA
  • PF_OutFlag2_DEPENDS_ON_UNREFERENCED_MASKS
  • PF_OutFlag2_OUTPUT_IS_WATERMARKED

After Effects uses this information for caching and optimization purposes, so try to respond as quickly as possible.

PF_Cmd_GPU_DEVICE_SETUP`

This selector can be called at any time by the host. It will be called not more than once for each GPU device.Multiple GPU devices may be in the setup state at one time.It will be called after GlobalSetup and before SequenceSetup.The intent is for the effect to do GPU initialization if necessary and to give the effect an opportunity to opt out of a GPU device based solely on the properties of that device, and not any render context (frame size, etc).If the effect rejects the GPU device it will get called for CPU render.PF_InData::what_gpu != PF_GPU_Framework_None is expected.Effect is expected to set one or both of the PF_OutFlag2_SUPPORTS_GPU_RENDER_Fxx flags in PF_OutData::out_flags2 if the device and framework in what_gpu is supported.Note that only PF_OutFlag2_SUPPORTS_GPU_RENDER_F32 will be in AE 16.0.Effects that do not set flags here will NOT be considered to support GPU rendering for any of these devices.PF_GPUDeviceSetupOutput::gpu_data is a plug-in owned pointer that must be released with a the PF_Cmd_GPU_DEVICE_SETDOWN selector.This pointer is also available at render time.

PF_Cmd_GPU_DEVICE_SETDOWN

Release any resources associated with gpu_data. In AE this will be called just before GPU device release.

typedef struct
{
    void *gpu_data; // effect must dispose.
    PF_GPU_Framework what_gpu;
    A_u_long device_index; // For use in conjunction with PrSDKGPUDeviceSuite
} PF_GPUDeviceSetdownInput;

typedef struct
{
    PF_GPUDeviceSetdownInput input;
} PF_GPUDeviceSetdownExtra;

PF_Cmd_GPU_SMART_RENDER_GPU

GPU equivalent to the existing PF_Cmd_SMART_RENDER selector.At render time, either the PF_Cmd_SMART_RENDER or the PF_Cmd_SMART_RENDER_GPU selector will be called, depending on whether the effect is expected to produce a CPU or GPU frame as output.PF_Cmd_SMART_RENDER_GPU will only be called when what_gpu != PF_GPU_Framework_None, and has effects on any input / output PF_LayerDef’s.All frame check-ins and check-outs will operate on GPU frames when this selector is in progress. Note PF_Cmd_SMART_RENDER shares the Extra structs.

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)
    void *pre_render_data;           // passed back from value placed in extra->output->pre_render_data during PF_Cmd_PRE_RENDER
    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)
} PF_SmartRenderInput;

typedef struct
{
    PF_SmartRenderInput *input;
    PF_SmartRenderCallbacks *cb;
} PF_SmartRenderExtra;

The what_gpu and device_index fields are in the extra input for GPU-related selectors indicates to the plug-in the GPU framework to be used for rendering.Input and output buffers will be prepared on this framework and device.The device, context, command queue, and other associated GPU state can be queried with PrSDKGPUDeviceSuite::GetDeviceInfo.what_gpu will be the same between PF_Cmd_SMART_PRE_RENDER and PF_Cmd_SMART_RENDER_GPU selector calls.