#How would one implement triangle texture mapping with SIMD?

4 messages · Page 1 of 1 (latest)

torn basin
#

assume that we’re using SSE2 in this case. my question is basically whether it’s possible to implement texture mapping of arbitrary UV coordinates on a triangle while using SIMD. I’ve been debating for a while how this would be done because to the best of my knowledge I can’t load integers from arbitrary positions in a buffer because the _mm_load instructions force me to load the integers contiguous in that address..

#

to help understand my question better, basically how would I do this, but vectorized:

{
    float weightV0 = GetWeightV0();
    float weightV1 = GetWeightV1();
    float weightV2 = GetWeightV2();

    // let's just assume these texcoords are in screen-space relating to a 128x128 texture:
    int textureX = (v0.texcoord.X * weightV0) + (v1.texcoord.X * weightV1) + (v2.texcoord.X * weightV2);
    int textureY = (v0.texcoord.Y * weightV0) + (v1.texcoord.Y * weightV1) + (v2.texcoord.Y * weightV2);

    WritePixel(p.x, p.y, textureData[textureX + textureY * 128]);
}```

the essence of my question is how would I access `textureData` at those indices using SIMD?
halcyon vapor
#

You can't. Not with SSE2. AVX2 has gather instructions for this usecase.

torn basin
#

oh, really?
if AVX2 was old enough I would be using that instead 😭. I just want to be as compatible as possible, and I feel SSE2 is supported by literally everyone's CPUs nowadays