Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for issue #98 (Cuda/Metal/OpenCL properties) #101

Closed
13 changes: 13 additions & 0 deletions HostSupport/src/ofxhImageEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ namespace OFX {
#ifdef OFX_SUPPORTS_OPENGLRENDER
{ kOfxImageEffectPropOpenGLRenderSupported, Property::eString, 1, false, "false"}, // OFX 1.3
#endif
{ kOfxImageEffectPropCudaRenderSupported, Property::eString, 1, false, "false" },
{ kOfxImageEffectPropCudaStreamSupported, Property::eString, 1, false, "false" },
{ kOfxImageEffectPropMetalRenderSupported, Property::eString, 1, false, "false" },
{ kOfxImageEffectPropOpenCLRenderSupported, Property::eString, 1, false, "false" },

Property::propSpecEnd
};

Expand Down Expand Up @@ -342,6 +347,10 @@ namespace OFX {
#ifdef OFX_SUPPORTS_OPENGLRENDER
{ kOfxImageEffectPropOpenGLRenderSupported, Property::eString, 1, false, "false"}, // OFX 1.4
#endif
{ kOfxImageEffectPropCudaRenderSupported, Property::eString, 1, false, "false" },
{ kOfxImageEffectPropCudaStreamSupported, Property::eString, 1, false, "false" },
{ kOfxImageEffectPropMetalRenderSupported, Property::eString, 1, false, "false" },
{ kOfxImageEffectPropOpenCLRenderSupported, Property::eString, 1, false, "false" },
Property::propSpecEnd
};

Expand Down Expand Up @@ -2714,6 +2723,10 @@ namespace OFX {
#endif
{ kOfxImageEffectPropRenderQualityDraft, Property::eInt, 1, true, "0" }, // OFX 1.4
{ kOfxImageEffectHostPropNativeOrigin, Property::eString, 0, true, kOfxHostNativeOriginBottomLeft }, // OFX 1.4
{ kOfxImageEffectPropCudaRenderSupported, Property::eString, 1, false, "false" },
{ kOfxImageEffectPropCudaStreamSupported, Property::eString, 1, false, "false" },
{ kOfxImageEffectPropMetalRenderSupported, Property::eString, 1, false, "false" },
{ kOfxImageEffectPropOpenCLRenderSupported, Property::eString, 1, false, "false" },
Property::propSpecEnd
};

Expand Down
12 changes: 12 additions & 0 deletions HostSupport/src/ofxhPropertySuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,11 @@ namespace OFX {
if(fetchTypedProperty(property, prop)) {
prop->setValue(value, index);
}
else {
# ifdef OFX_DEBUG_PROPERTIES
std::cout << "OFX: setProperty " << property << "[" << index << "] ignored because host property not defined" << std::endl;
# endif
}
}
catch(...) {}
}
Expand All @@ -592,6 +597,11 @@ namespace OFX {
if(fetchTypedProperty(property, prop)) {
prop->setValueN(value, count);
}
else {
# ifdef OFX_DEBUG_PROPERTIES
std::cout << "OFX: setPropertyN " << property << " ignored because host property not defined" << std::endl;
# endif
}
}
catch(...) {}
}
Expand Down Expand Up @@ -792,6 +802,7 @@ namespace OFX {
PropertyTemplate<T> *prop = 0;
if(!thisSet->fetchTypedProperty(property, prop, false)) {
# ifdef OFX_DEBUG_PROPERTIES
std::cout << "OFX: propSet " << property << "[" << index << "] ignored because effect property not defined" << std::endl;
std::cout << ' ' << StatStr(kOfxStatErrUnknown) << std::endl;
# endif
return kOfxStatErrUnknown;
Expand Down Expand Up @@ -839,6 +850,7 @@ namespace OFX {
PropertyTemplate<T> *prop = 0;
if(!thisSet->fetchTypedProperty(property, prop, false)) {
# ifdef OFX_DEBUG_PROPERTIES
std::cout << "OFX: propSetN " << property << " ignored because effect property not defined" << std::endl;
std::cout << ' ' << StatStr(kOfxStatErrUnknown) << std::endl;
# endif
return kOfxStatErrUnknown;
Expand Down
174 changes: 171 additions & 3 deletions include/ofxImageEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -1252,9 +1252,15 @@ This contains the duration of the plug-in effect, in frames.
/** @brief The pixel data pointer of an image.

- Type - pointer X 1
- Property Set - an image instance (read only)
- Property Set - an image instance (read only)

This property contains one of:
- a pointer to memory that is the lower left hand corner of an image
- a pointer to Cuda memory, if the Render action arguments includes kOfxImageEffectPropCudaEnabled=1
- an id<MTLBuffer>, if the Render action arguments includes kOfxImageEffectPropMetalEnabled=1
- a cl_mem, if the Render action arguments includes kOfxImageEffectPropOpenCLEnabled=1

This property contains a pointer to memory that is the lower left hand corner of an image.
See \ref kOfxImageEffectPropCudaEnabled, \ref kOfxImageEffectPropMetalEnabled and \ref kOfxImageEffectPropOpenCLEnabled
*/
#define kOfxImagePropData "OfxImagePropData"

Expand Down Expand Up @@ -1300,7 +1306,7 @@ For various alignment reasons, a row of pixels may need to be padded at the end
This property indicates the number of bytes in a row of pixels. This will be at least sizeof(PIXEL) * (bounds.x2-bounds.x1). Where bounds
is fetched from the ::kOfxImagePropBounds property.

Note that row bytes can be negative, which allows hosts with a native top down row order to pass image into OFX without having to repack pixels.
Note that (for CPU images only, not Cuda/Metal/OpenCL buffers, nor textures accessed via the OpenGL Render Suite) row bytes can be negative, which allows hosts with a native top down row order to pass image into OFX without having to repack pixels.
*/
#define kOfxImagePropRowBytes "OfxImagePropRowBytes"

Expand Down Expand Up @@ -1394,6 +1400,168 @@ This will be in \ref PixelCoordinates
*/
#define kOfxImageEffectPropRenderWindow "OfxImageEffectPropRenderWindow"

/** @brief Indicates whether a host or plugin can support Cuda render

- Type - string X 1
- Property Set - plugin descriptor (read/write), host descriptor (read only)
- Default - "false"
- Valid Values - This must be one of
- "false" - the host or plugin does not support Cuda render
- "true" - the host or plugin can support Cuda render
*/
#define kOfxImageEffectPropCudaRenderSupported "OfxImageEffectPropCudaRenderSupported"

/** @brief Indicates that an image effect SHOULD use Cuda render in
the current action

If a plugin and host have both set
kOfxImageEffectPropCudaRenderSupported="true" then the host MAY set
this property to indicate that it is passing images as Cuda memory
pointers.

- Type - int X 1
- Property Set - inArgs property set of the kOfxImageEffectActionRender action
- Valid Values
- 0 indicates that the kOfxImagePropData of each image of each clip
is a CPU memory pointer.
- 1 indicates that the kOfxImagePropData of each image of each clip
is a Cuda memory pointer.
*/
#define kOfxImageEffectPropCudaEnabled "OfxImageEffectPropCudaEnabled"

/** @brief Indicates whether a host or plugin can support Cuda streams

- Type - string X 1
- Property Set - plugin descriptor (read/write), host descriptor (read only)
- Default - "false"
- Valid Values - This must be one of
- "false" - in which case the host or plugin does not support Cuda streams
- "true" - which means a host or plugin can support Cuda streams

*/
#define kOfxImageEffectPropCudaStreamSupported "OfxImageEffectPropCudaStreamSupported"

/** @brief The Cuda stream to be used for rendering

- Type - pointer X 1
- Property Set - inArgs property set of the kOfxImageEffectActionRender action

This property will only be set if the host and plugin both support Cuda streams.

If set:

- this property contains a pointer to the stream of Cuda render (cudaStream_t).
In order to use it, reinterpret_cast<cudaStream_t>(pointer) is needed.

- the plugin SHOULD ensure that its render action enqueues any
asynchronous Cuda operations onto the supplied queue.

- the plugin SHOULD NOT wait for final asynchronous operations to
complete before returning from the render action, and SHOULD NOT
call cudaDeviceSynchronize() at any time.

If not set:

- the plugin SHOULD ensure that any asynchronous operations it
enqueues have completed before returning from the render action.
*/
#define kOfxImageEffectPropCudaStream "OfxImageEffectPropCudaStream"

/** @brief Indicates whether a host or plugin can support Metal render

- Type - string X 1
- Property Set - plugin descriptor (read/write), host descriptor (read only)
- Default - "false"
- Valid Values - This must be one of
- "false" - the host or plugin does not support Metal render
- "true" - the host or plugin can support Metal render
*/

#define kOfxImageEffectPropMetalRenderSupported "OfxImageEffectPropMetalRenderSupported"

/** @brief Indicates that an image effect SHOULD use Metal render in
the current action

If a plugin and host have both set
kOfxImageEffectPropMetalRenderSupported="true" then the host MAY
set this property to indicate that it is passing images as Metal
buffers.

- Type - int X 1
- Property Set - inArgs property set of the kOfxImageEffectActionRender action
- Valid Values
- 0 indicates that the kOfxImagePropData of each image of each clip
is a CPU memory pointer.
- 1 indicates that the kOfxImagePropData of each image of each clip
is a Metal id<MTLBuffer>.
*/
#define kOfxImageEffectPropMetalEnabled "OfxImageEffectPropMetalEnabled"

/** @brief The command queue of Metal render

- Type - pointer X 1
- Property Set - inArgs property set of the kOfxImageEffectActionRender action

This property contains a pointer to the command queue to be used for
Metal rendering (id<MTLCommandQueue>). In order to use it,
reinterpret_cast<id<MTLCommandQueue>>(pointer) is needed.

The plugin SHOULD ensure that its render action enqueues any
asynchronous Metal operations onto the supplied queue.

The plugin SHOULD NOT wait for final asynchronous operations to
complete before returning from the render action.
*/
#define kOfxImageEffectPropMetalCommandQueue "OfxImageEffectPropMetalCommandQueue"

/** @brief Indicates whether a host or plugin can support OpenCL render

- Type - string X 1
- Property Set - plugin descriptor (read/write), host descriptor (read only)
- Default - "false"
- Valid Values - This must be one of
- "false" - the host or plugin does not support OpenCL render
- "true" - the host or plugin can support OpenCL render
*/

#define kOfxImageEffectPropOpenCLRenderSupported "OfxImageEffectPropOpenCLRenderSupported"

/** @brief Indicates that an image effect SHOULD use OpenCL render in
the current action

If a plugin and host have both set
kOfxImageEffectPropOpenCLRenderSupported="true" then the host MAY
set this property to indicate that it is passing images as OpenCL
buffers.

- Type - int X 1
- Property Set - inArgs property set of the kOfxImageEffectActionRender action
- Valid Values
- 0 indicates that the kOfxImagePropData of each image of each clip
is a CPU memory pointer.
- 1 indicates that the kOfxImagePropData of each image of each clip
is a cl_mem.
*/
#define kOfxImageEffectPropOpenCLEnabled "OfxImageEffectPropOpenCLEnabled"

/** @brief The command queue of OpenCL render

- Type - pointer X 1
- Property Set - inArgs property set of the kOfxImageEffectActionRender action

This property contains a pointer to the command queue to be used for
Metal rendering (cl_command_queue). In order to use it,
reinterpret_cast<cl_command_queue>(pointer) is needed.

The plugin SHOULD ensure that its render action enqueues any
asynchronous OpenCL operations onto the supplied queue.

The plugin SHOULD NOT wait for final asynchronous operations to
complete before returning from the render action.
*/
#define kOfxImageEffectPropOpenCLCommandQueue "OfxImageEffectPropOpenCLCommandQueue"



/** String used to label imagery as having no fields */
#define kOfxImageFieldNone "OfxFieldNone"
Expand Down
16 changes: 8 additions & 8 deletions include/ofxOpenGLRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ clipLoadTexture
/** @brief Request the host to minimize its GPU resource load

When a plugin fails to allocate GPU resources, it can call this function to
request the host to flush it's GPU resources if it holds any.
request the host to flush its GPU resources if it holds any.
After the function the plugin can try again to allocate resources which then
might succeed if the host actually has released anything.

Expand Down Expand Up @@ -390,32 +390,32 @@ The OfxOpenGLRenderSuite allows image effects to use OpenGL commands
(hopefully backed by a GPU) to accelerate rendering
of their outputs. The basic scheme is simple....
- An effect indicates it wants to use OpenGL acceleration by setting the
::kOfxImageEffectOpenGLRenderSupported flag on it's descriptor
::kOfxImageEffectPropOpenGLRenderSupported flag on its descriptor
- A host indicates it supports OpenGL acceleration by setting
::kOfxImageEffectOpenGLRenderSupported on it's descriptor
::kOfxImageEffectPropOpenGLRenderSupported on its descriptor
- In an effect's ::kOfxImageEffectActionGetClipPreferences action, an
effect indicates what clips it will be loading images from onto the GPU's
memory during an effect's ::kOfxImageEffectActionRender action.

@section ofxOpenGLRenderHouseKeeping OpenGL House Keeping

If a host supports OpenGL rendering then it flags this with the string
property ::kOfxImageEffectOpenGLRenderSupported on its descriptor property
property ::kOfxImageEffectPropOpenGLRenderSupported on its descriptor property
set. Effects that cannot run without OpenGL support should examine this in
::kOfxActionDescribe action and return a ::kOfxStatErrMissingHostFeature
status flag if it is not set to "true".

Effects flag to a host that they support OpenGL rendering by setting the
string property ::kOfxImageEffectOpenGLRenderSupported on their effect
string property ::kOfxImageEffectPropOpenGLRenderSupported on their effect
descriptor during the ::kOfxActionDescribe action. Effects can work in three
ways....
- purely on CPUs without any OpenGL support at all, in which case they
should set ::kOfxImageEffectOpenGLRenderSupported to be "false" (the
should set ::kOfxImageEffectPropOpenGLRenderSupported to be "false" (the
default),
- on CPUs but with optional OpenGL support, in which case they should set
::kOfxImageEffectOpenGLRenderSupported to be "true",
::kOfxImageEffectPropOpenGLRenderSupported to be "true",
- only with OpenGL support, in which case they should set
::kOfxImageEffectOpenGLRenderSupported to be "needed".
::kOfxImageEffectPropOpenGLRenderSupported to be "needed".

Hosts can examine this flag and respond to it appropriately.

Expand Down