Template "implicit instantiation" error using Metal API with Imageblocks

303 Views Asked by At

In the following metal performance shader code:

#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;

struct MeshVertex
{
    half3 worldPosition3d;
    half2 cameraPosition2d;
};

kernel void MeshImageblockShader_kernelFunction(
                 imageblock<MeshVertex>                 meshVertex_imageblock,
                 texture2d<float, access::read_write>   trueDepthTexture       [[ texture(0) ]],
        constant float3x3&                              positionInThreadgroup  [[ thread_position_in_threadgroup ]],
                 ushort2                                positionInGrid         [[ threadgroup_position_in_grid ]])
{

    threadgroup_imageblock MeshVertex* meshVertex_threadgroupImageblock = meshVertex_imageblock.data(positionInThreadgroup);
    imageblock_slice<half3> worldPosition3d_slice = meshVertex_imageblock.slice(meshVertex_threadgroupImageblock->worldPosition3d);    
}

I am getting two errors on the last code line:

(!) implicit instantiation of undefined template 'metal::imageblock_slice<half __attribute__((ext_vector_type(3))), metal::imageblock_layout_explicit, void>'
(!) too few template arguments for class template 'imageblock_slice'

I'm trying to follow the tech talk example for "Metal 2 on a!! - Imageblocks" at https://developer.apple.com/videos/play/tech-talks/603/ (The code sample is given at 3:25 into the video.)

I am unable to find any code examples on the internet using imageblocks.

Can anyone suggest some sample code, or tell me why this is not compiling?

2

There are 2 best solutions below

0
On

The imageblock_slice<T> template is not compatible with half3.

Changing to imageblock_slice<half4> fixes this.

0
On

You missed #include <metal_imageblocks> on the top.