I have heard many times that if statements in shaders slow down the gpu massively. But I also heard that texture samples are very expensive.

Which one is more endurable? Which one is less impactful?

I am asking, because I need to decide on if I should multiply a value by 0, or put an if statement.

  • Efi (nap pet) 🦊💤@chitter.xyz
    link
    fedilink
    arrow-up
    1
    ·
    6 days ago

    @Smorty because gpus can’t feasibly do speculative execution, forking is more expensive than a lookup, which can be done in parallel and cached, but of course, it depends on what you’re testing and what you’re sampling
    it’s not the same to test for one equality than a complex function call, and it’s not the same thing sampling a small or big texture, with or without mipmap levels, aggregation, etc