CIKernel compiler produces invalid filter when multiple kernels are specified in a single file

Originator:craig.hockenberry
Number:rdar://21638081 Date Originated:01-Jul-2015 01:03 PM
Status:Open Resolved:
Product:OS X Product Version:10.11 (15A204h)
Classification:Serious Bug Reproducible:Always
 
Summary:

A .cikernel file that uses more than one “kernel” annotation does not produce any result or any type of error.

Steps to Reproduce:

Create a .cikernel with the following text:

kernel vec4 Test (sampler src)
{
    return vec4(0.0, 1.0, 0.0, 0.0);
}

kernel vec4 Gradient (sampler src)
{
    vec4 test = Test(src);
    
    float red = 0.0;
    float green = 0.0;
    float blue = 0.0;
    float alpha = 1.0;
    
    red = test.r;
    green = test.g;
    blue = test.b;
    
    return vec4(red, green, blue, alpha);
}

Then process an image with CIKernel created with:

    NSArray *kernels = [CIKernel kernelsWithString:kernelCode];
    CIKernel *myKernel = [kernels lastObject];

Expected Results:

A Core Image filter that returns a green image.

Actual Results:

A Core Image filter that does nothing: no errors and no image processing.

Regression:

This code works fine in Yosemite 10.10 and prior.

Notes:

The documentation in CIKernel.h states:

/* The string 's' should contain a program in the CoreImage dialect
 * of the OpenGL Shading Language. Each function marked as a kernel is
 * converted to a CIKernel object, all objects are then returned in
 * an array. */
+ (NSArray *)kernelsWithString:(NSString *)s;

The workaround is to remove the “kernel” annotation from the Test function (so that only one remains.) This is far from obvious since there is no error returned while compiling the kernel (with the new LLVM backend) or while processing the image (with Metal.)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!