Sofiane Benzait
Sofiane Benzait

Reputation: 39

How to have access to pointer to pointer to varying data (T**) using ISPC intel compiler

I am learning how to use ISPC, I understood how to efficiently use uniform and varying on common data, but I struggle to find out how to use uniform and varying with pointers (and pointers to pointer T**).

This is a example which I would like to understand :

export void functionA(uniform const int16** uniform imageList) {

uniform zu = ... ;
uniform const int16* image_zu = imageList[zu];
functionB(image_zu);
}

void functionB(uniform int16* image_zu) {
varying xy = ...
varying data = image_zu[xy] ;

print("xy: % ; data ------> %\n", xy, data );
print("\n");
}

the output is

[131072,((131073)),((131074)),((131075)),((131076)),((131077)),((131078)),((131079))] ------> [1083,((1083)),((1083)),((1083)),((1083)),((1083)),((1083)),((1083))]

To my point of view uniform const int16** uniform imageList imageList is a uniform pointer pointing to uniform pointer that point to varying data... Its seems that even if data is type as varying, all the lanes have the same data which is not the behavior of a varying data. I don't know how to understand that and I did not find any good solution on internet so I am here

I search on internet, I even ask to GPT but i did not found anything

Upvotes: 1

Views: 62

Answers (1)

Alon Alush
Alon Alush

Reputation: 968

You could try this:

export void samePointerDifferentOffsets(uniform const int16 **uniform imageList,
                                        uniform int   chosenIndex,
                                        varying int   offsets)
{
    
    imageList:
    uniform const int16 *basePtr = imageList[chosenIndex];

    // basePtr is uniform. Indexing it by varying `offsets` -> gather
    varying int16 data = basePtr[offsets];

    print("lane=% : offsets=% : data=%\n", programIndex, offsets, data);
}

If you run this with, say, offsets = [0,1,2,3,4,5,6,7] on an 8‐wide ISPC target, you should see distinct data per lane (assuming the underlying array is not constant at those offsets).

Upvotes: 1

Related Questions